GATE Computer ScienceVery hardGATE CS (PYQ pattern)
For G: S → x S y | x y | S S, which statements are true? I. G is ambiguous. II. The canonical LR(1) table has more multiply-defined cells than the LALR(1) table. III. The LALR(1) automaton has fewer states than the canonical LR(1) automaton. IV. G is LR(0).
- A. I and III only
- B. I only
- C. I, II and III only
- D. II, III and IV only
Correct answer: C. I, II and III only
x y x y x y has two trees ((S S) S and S (S S)), so I holds and no LR table is conflict-free (IV false). The clash is in the state reached after S S, between reducing S → S S and shifting x. In canonical LR(1) that core appears twice (lookahead set with $ at top level and with y inside x…y), giving 2 conflicting cells; LALR merges them into 1. LR(1) has 12 states against 7.
More Compiler Design questions
- A lexer uses longest match, breaking ties in favour of the rule listed first, with rules: KW = if | then; ID = [a-z][a-z0-9]; NUM =…
- G: S → id | id [ E ] | id ( E ); E → id. G′ is obtained from G by left factoring S. Which statements are true? I. G is LL(1). II. G′ is…
- Construct the SLR(1) parsing table of S → a B | b A; A → a | a S | b A A; B → b | b S | a B B (augmented). In how many states of the…
- An NFA over {a, b} has states 0 to 4, start state 0, and these moves (a missing move means no transition): δ(0,a)={1,2}; δ(0,b)={0,1,2}…
- Build the SLR(1) table for S → ( L ) | x; L → S | L , S (augmented with S′ → S). The ACTION part has a column for each of (, ), x, , and…
- int x = 1; void p() { x = x + 10; } void r() { print(x); } void q() { int x = 5; p(); r(); } main() { q(); r(); print(x); } What is…