Precedence

  • Precedence: Which of 2 different operators happens first?
  • 
                3+4*5  (3+4)*5  or  3+(4*5)
                3*4+5  (3*4)+5  or  3*(4+5)
                
    • Parenthesis have the highest precedence
    • * has more precedence than +
    • * has the same precedence as /

Associativity & Ambiguity

  • Associativity: which of 2 same operators happens first?
  • 
                3-4-5  (3-4)-5  or  3-(4-5)  - is left assoc
                x=y=z  (x=y)=z  or  x=(y=z)  = is right assoc
                2^3^4  (2^3)^4  or  2^(3^4)  ^ is right assoc
                3/4/5  (3/4)/5  or  3/(4/5)  / is left assoc
                
  • Ambiguous: Grammar lets multiple trees happen for a program