Lexical Analysis: GATE CS Previous Year Questions

Lexical Analysis · Compiler Design

8 questions · asked in 7 of 27 years (2000–2026)

MCQ 7 · NAT 11-mark 7 · 2-mark 1

2000Questions per year2026

Questions 1–5 of 8

Q1GATE 2026 (Session 2)1 markNAT
A lexical analyzer uses the following token definitions

letter→[A−Za−z]{letter → [A-Za-z]}
digit→[0−9]{digit → [0-9]}
id→letter(letter∣digit)∗{id → letter (letter | digit)^*}
number→digit+{number → digit^{+}}
ws→(blank∣tab∣newline)+{ws → (blank | tab| newline)^{+}}

For the string given below,

x123mm78 y 7z zz5 14A8H AaYcD x1 \quad 23mm \quad 78 \quad \text{ y } \quad 7 z \quad \text { zz5 } \quad 14 A \quad 8 H \quad \text { AaYcD }

the number of tokens (excluding ws) that will be produced by the lexical analyzer is ________. (answer in integer)

Q2GATE 2025 (Session 1)1 markMCQ−0.33 if wrong
Which ONE of the following statements is FALSE regarding the symbol table?

Q3GATE 20201 markMCQ−0.33 if wrong
Consider the following statements.

I. Symbol table is accessed only during lexical analysis and syntax analysis.
II. Compilers for programming languages that support recursion necessarily need heap storage for memory allocation in the run-time environment.
III. Errors violating the condition 'any variable must be declared before its use' are detected during syntax analysis.

Which of the above statements is/are TRUE?

Q4GATE 20182 marksMCQ−0.67 if wrong
A lexical analyzer uses the following patterns to recognize three tokens T1,T2,  and  T3T_{1}, T_{2}, \; and \; T_{3} over the alphabet {a,b,c}.

T1:a?(b∣c)∗aT_{1}:a?(b|c)^* a
T2:b?(a∣c)∗bT_{2}:b?(a|c)^* b
T3:c?(b∣a)∗cT_{3}:c?(b|a)^* c

Note that 'x?' means 0 or 1 occurrence of the symbol x. Note also that the analyzer outputs the token that matches the longest possible prefix.

If the string bbaacabc is processed by the analyzer, which one of the following is the sequence of tokens it outputs?

Q5GATE 20111 markMCQ−0.33 if wrong
The lexical analysis for a modern computer language such as Java needs the power of which one of the following machine models in a necessary and sufficient sense?

Keep practising

Topics in Compiler Design

All CS topics ›