GATE Computer ScienceVery hardGATE CS
A syntax-directed translation scheme prints as it reduces: E → T + E { print('+') } | T; T → F * T { print('*') } | F; F → id { print(id.name) }. The parser is bottom-up and executes each action when its production is reduced. What is printed for the input a+b*c+d*e*f?
- A. abc*def++**
- B. abc*def*+*+
- C. abc*+def**+
- D. abc*def**++
Correct answer: D. abc*def**++
Both operators are right associative: a + (b*c + (d*(e*f))). Printing the operands as F is reduced and each operator after both its operands gives a b c * d e f * * + +, i.e. abc*def**++.
More Compiler Design questions
- A lexical rule recognises the language (ab | abc | c)(bc | a) over {a, b, c}. How many states does the minimal complete DFA (dead state…
- For the statement a = b (−c) + b (−c), common subexpressions are shared (so −c and b (−c) are each computed once) and the code is stored…
- Grammar: E → E + T | T; T → T F | F; F → ( E ) | id. An SLR(1) parser parses id + id ( id + id ) id. Counting every shift, every reduce…
- A table-driven predictive parser for E → T E'; E' → + T E' | ε; T → F T'; T' → F T' | ε; F → ( E ) | id parses ( id + id ) id + id. One…
- An array A[2..6][−1..4][0..5] of 4-byte elements has base address 1000. The address of A[4][2][3] is computed in row-major order and…
- A scanner discards comments, which begin with / and end at the FIRST / (comments do not nest). Identifiers are letters, and and / are…