GATE Computer ScienceVery hardGATE CS (PYQ pattern)
A Pascal-like scanner uses longest match (ties to the earlier rule) with rules: FLOAT = [0-9]+\.[0-9]*; INT = [0-9]+; RANGE = \.\.; DOT = \.; ID = [a-z]+. How many tokens are produced for the input "1..5.x3.7..2" (no spaces)?
- A. 6
- B. 9
- C. 8
- D. 7
Correct answer: D. 7
Tokens: 1. | . | 5. | x | 3.7 | .. | 2. '1..5' scans as FLOAT '1.' then DOT, then INT 5, because the longest match at '1' is '1.' (2 chars) rather than INT '1'.
More Compiler Design questions
- SDD: S → ( S S ) | a. S.d is inherited: root d = 0, children get parent.d + 1. For a → a: S.v = S.d if S.d is even, otherwise −S.d. For S…
- int i = 1; int A[1..4] = {4, 7, 2, 9}; void swap(x, y) { int t = x; x = y; y = t; } The call swap(i, A[i]) is made. The parameters are…
- For S′ → S; S → A | x b; A → a A b | B; B → x, what is the LALR(1) lookahead set of the item B → x · in the state reached from the start…
- int x = 1; int a() { return x; } int b(int n) { int x = n 10; if (n == 0) return a(); return b(n - 1) + a(); } What does b(2) return under…
- A basic block is converted to a DAG with value numbering (+ and commutative; a new leaf is made for each variable's initial value; a…
- A basic block has 8 three-address statements, of which 3 compute a triple identical to an earlier one. A compiler stores it as (i)…