GATE Computer ScienceVery hardGATE CS (PYQ pattern)
A scanner (longest match, ties to the earlier rule) has rules: COMMENT = //[^newline]*; STR = "[^"]*"; DIV = /; EQ = ==; ASSIGN = =; ID = [a-z]+; white space (including newline) is skipped. How many tokens (excluding white space) does it produce for the input whose first line is x=="a//b"/y//z/w and whose second line is =q ?
- A. 9
- B. 8
- C. 7
- D. 10
Correct answer: B. 8
Tokens: x | == | "a//b" | / | y | //z/w | = | q; the // inside the string literal does not start a comment because the string is matched first from the quote, and the real // swallows 'z/w' to the end of the line.
More Compiler Design questions
- SDD for S → ( S1 S2 ) | a: the inherited attribute S.n is 1 at the root, and for S → ( S1 S2 ) the rules are S1.n = 2 × S.n and S2.n = 2 ×…
- Minimal SSA form (φ-functions placed at the iterated dominance frontier of each variable's definition blocks, without liveness pruning…
- Which of the following about run-time environments is/are true? I. An access (static) link points to the frame of the lexically enclosing…
- For S′ → S; S → S ( S ) | ε, LALR(1) merges canonical LR(1) states with equal cores. The LALR state whose only item is S → S ( S ) · is…
- In 1: i = 0; 2: L1: if i >= n goto L3; 3: i = i + 1; 4: if i > k goto L1; 5: j = j + i; 6: goto L1; 7: L3: return j, how many back edges…
- An SLR(1) shift-reduce parser for E → T E'; E' → + T E' | ε; T → F T'; T' → F T' | ε; F → ( E ) | id parses "id + id id". Each shift and…