GATE / CS ARCHIVE

GATE CSE 2005 / QUESTION 83a

Yacc default ambiguity resolution

Compiler Design · Parsing & Syntax Analysis · Full GATE CSE 2005 paper

GATE 2005, Q83a 2 marks · MCQ
Report issue

Parsing & Syntax Analysis

Question 83a, GATE 2005: Expression grammar E→number | E+E | E×E has the usual synthesized arithmetic values and is given to yacc without precedence/associativity declarations. Printed 83(a): yacc A detects/eliminates recursion; B resolves reduce/reduce conflict; C resolves shift/reduce in favor of shift; D resolves shift/reduce in favor of reduce.
Question 83a, GATE 2005: Expression grammar E→number | E+E | E×E has the usual synthesized arithmetic values and is given to yacc without precedence/associativity declarations. Printed 83(a): yacc A detects/eliminates recursion; B resolves reduce/reduce conflict; C resolves shift/reduce in favor of shift; D resolves shift/reduce in favor of reduce.
Question 83a, GATE 2005: Expression grammar E→number | E+E | E×E has the usual synthesized arithmetic values and is given to yacc without precedence/associativity declarations. Printed 83(a): yacc A detects/eliminates recursion; B resolves reduce/reduce conflict; C resolves shift/reduce in favor of shift; D resolves shift/reduce in favor of reduce.
Tap to enlarge
Your answer
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.

Original paper, page 12