GATE Computer ScienceHardGATE CS (PYQ pattern)
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 LL(1). III. G is LR(0). IV. G is SLR(1).
- A. I, II and IV only
- B. II, III and IV only
- C. IV only
- D. II and IV only
Correct answer: D. II and IV only
I: all three S-alternatives start with id. II: G′ is S → id R; R → [ E ] | ( E ) | ε, and FOLLOW(R) = {$} is disjoint from [ and (. III: after id the LR(0) state holds S → id· beside shifts on [ and (. IV: FOLLOW(S) = {$}, so SLR reduces only on $ and the clash disappears.
More Compiler Design questions
- 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…
- Each assignment is a definition named by its statement number. In 1: s = 0; 2: i = 0; 3: L1: if i >= n goto L4; 4: if a > 0 goto L2; 5: s…
- A basic block is converted to a DAG using value numbering, treating + and as commutative, reusing an existing node when the same operator…