Ambiguous Grammars
- An ambiguous grammar permits more than one parse tree for some sentences. For example, parsing xxx with the following grammar:
S AA
A x | xx
- But useful:
expression expression binop expression | integer
binop + | - | * | /
- Use rules (e.g. BODMAS) to disambiguate, and/or rewrite:
expression expression termop term | term
termop + | -
term term factorop integer | integer
factorop * | /