Similar questions 1 more →
Parsing & Syntax Analysis



Answer & solution
Answer: C (no official key was published)
The grammar E→number | E+E | E×E is ambiguous. After recognizing E+E or E×E, a following operator permits either reduction of the completed expression or shifting to build the right operand further. This is a shift/reduce conflict. With no precedence/associativity declarations, yacc defaults to shifting, option C; left recursion itself is valid for LR parsing.
After E+E has been recognized and a further operator is seen, the parser can either reduce the completed expression now or shift the operator to extend its right operand. The grammar does not specify which grouping is intended, hence a shift/reduce conflict. yacc’s default selects shift. Left recursion is supported naturally by LR parsing and is not removed automatically; no two distinct completed production reductions cause this particular ambiguity.