CS 541 Lecture -*- Outline -*- * Ambiguity ** Motivation: Expression grammars ------------ AN AMBIGUOUS GRAMMAR E ::= id | E + E | E * E | ( E ) id ::= a | b | c ------------- What does "a+b*c" mean? a+(b*c) or (a+b)*c? *** How parse trees are built E E | | ________|_________ _______|_______ E | E E | E | | | | | | id + _____|______ ______|____ * id | E | E E | E | | | | | | | | | | id * id id + id | a b c a b c *** precedence: higher precedence operators bind more tightly * has higher precedence than + ** Ambiguous grammar a grammar is ambiguous iff it has a sentence with two (different) parse trees example: above expression grammar ** A fix left-associative, expression grammar with + lower precedence E ::= E + term | term term ::= term * factor | factor factor ::= id | E