GATE Computer ScienceVery hardGATE CS (PYQ pattern)
A yacc-generated parser for E → E op E | num uses the precedence declarations %left '*'; %right '-'; %left '+' (in this order, so + binds tightest); later declarations bind tighter. The operators +, - and * have their usual arithmetic meaning. What does the parser compute for "2 * 8 - 3 - 1 + 4 * 2"?
- A. 20
- B. 32
- C. 28
- D. 40
Correct answer: D. 40
Apply the declared levels and associativity (not school precedence): the parenthesised grouping implied by the declarations evaluates to 40; school precedence would give 20.
More Compiler Design questions
- Consider strings containing both ab and bb as substrings in either order (overlaps allowed). How many states does the minimal complete DFA…
- G1: L → L , x | x and G2: L → x , L | x generate the same language. A shift-reduce (LR) parser parses "x , x , x , x , x" (five x's) with…
- Productions of the grammar are numbered: (1) E → E + T; (2) E → T; (3) T → T F; (4) T → F; (5) F → ( E ); (6) F → id. An LR parser parses…
- In 1: i = 0; 2: L1: if i >= n goto L3; 3: if i > k goto L2; 4: t = a b; 5: x = t + 1; 6: L2: y = a + b; 7: i = i + 1; 8: goto L1; 9: L3…
- For the grammar S → X Y Z; X → a X | ε; Y → b Y | X; Z → c | ε, what is FIRST(S)? (ε counts as a member if S is nullable.)
- The statement r = (a + b) (b + a) − (a + b) / c is turned into a DAG (+ and commutative, − and / not), and three-address code is generated…