GATE Computer ScienceModerateGATE CS
In the expression a = (b + c) * (b + c) - d / (b + c), the numbers of operator (internal) nodes in the syntax tree for the right-hand side and in its optimised DAG are respectively:
- A. 3 and 6
- B. 5 and 6
- C. 4 and 7
- D. 6 and 4
Correct answer: D. 6 and 4
The tree has +, + and * for the first term, + and / for the second, and the final -: 6 operator nodes. The DAG shares the single node b + c, leaving +, *, / and -, i.e. 4 nodes. The option order is tree then DAG.
More Compiler Design questions
- A C lexer applies the longest-match (maximal munch) rule. The number of tokens in the statement x = a---bc++; is:
- Which of the following grammars are LL(1)? (I) S → a S b | ε. (II) S → a S a | a. (III) S → A B, A → a | ε, B → a | b. (IV) S → a S | b S…
- Consider this pseudo-code (arrays are 1-based): i = 1; a = [5, 6, 7]; procedure P(x, y) { x = x + 1; y = y 2; } P(i, a[i]); print(i, a[1]…
- A C-like scanner uses maximal munch with these tokens: identifiers (letters and digits, starting with a letter) and the operators ++…
- A generated scanner for the token set { a, abcd, b, c, d } always returns the longest accepting prefix, and if the DFA reaches the dead…
- A scanner generator is given the rules, in this order: (1) if → IF; (2) [a-z][a-z0-9] → ID; (3) [0-9]+ → NUM. It uses the longest match…