GATE Computer ScienceHardGATE CS (PYQ pattern)

A yacc-generated parser for E → E op E | num uses the precedence declarations %right '+' '-'; %left '*'; later declarations bind tighter. The operators + - * ^ have their usual arithmetic meaning. What does the parser compute for "3 + 2 * 4 - 6 - 1 * 2"?

  1. A. 3
  2. B. 7
  3. C. 26
  4. D. 11

Correct answer: B. 7

Apply the declared levels and associativity (not school precedence): the parenthesised grouping implied by the declarations evaluates to 7; school precedence would give 3.

More Compiler Design questions

Exams that ask this topic