GATE Computer ScienceHardGATE CS (PYQ pattern)
An SDD uses N → B N1 { N.val = B.val + 2 × N1.val } | B { N.val = B.val } and B → 0 { B.val = 0 } | 1 { B.val = 1 }. What is N.val at the root for the input "1 1 0 1", and what is it for "1 0 1 1"?
- A. 11 and 13
- B. 13 and 11
- C. 13 and 13
- D. 11 and 11
Correct answer: A. 11 and 13
The right-recursive rule weights the leftmost bit by 1 and each later bit by twice the previous weight, so the string is read least-significant bit first. 1 1 0 1 → 1 + 2(1 + 2(0 + 2·1)) = 11, and 1 0 1 1 → 1 + 2(0 + 2(1 + 2·1)) = 13. (Reading them as ordinary binary gives 13 and 11, the swapped answer.)
More Compiler Design questions
- A SLR(1) parser for the augmented grammar S → id | id [ E ] | id ( E ); E → id parses "id [ id ]". What is the maximum number of grammar…
- Partition into basic blocks (leaders: the first statement, every jump target, every statement right after a jump): 1: i = 0; 2: L1: if i >…
- Consider the strings over {a,b} that start and end with different symbols. How many states does the minimal complete DFA (including a dead…
- A table-driven LL(1) parser for S → a S A | ε; A → b S | c parses "a a b a c c". Each expansion of a non-terminal and each match of a…
- For G: S → a A b | A a; A → a | ε (which generates a, aa, ab and aab), which statements are true? I. G is LL(2). II. G is LL(3). III. G is…
- Let G2: S → A A; A → a A | b and G3: S → A A A; A → a A | b. For each, how many more states does the canonical LR(1) automaton have than…