Lexical Analysis questions

Q35

GATE CS 2026 CS-2Lexical AnalysisNAT1 mark
A lexical analyzer uses the following token definitions
* letter→[A−Za−z]letter \rightarrow [A - Za - z]
* digit→[0−9]digit \rightarrow [0 - 9]
* id→letter(letter∣digit)∗id \rightarrow letter (letter \mid digit)^*
* number→digit+number \rightarrow digit^+
* ws→(blank∣tab∣newline)+ws \rightarrow (blank \mid tab \mid newline)^+

For the string given below,

x1  23mm  78  y  7z  zz5  14A  8H  AaYcDx1 \; 23mm \; 78 \; y \; 7z \; zz5 \; 14A \; 8H \; AaYcD

the number of tokens (excluding wsws) that will be produced by the lexical analyzer is __________. (answer in integer)
Show answer without attempting

Answer: 13

Q12

GATE CS 2025 CS-1Lexical AnalysisMCQ1 mark−1/3 if wrong
Which ONE of the following statements is FALSE regarding the symbol table?
Show answer without attempting

Answer: C

Q21

GATE CS 2024 CS-2Lexical AnalysisMCQ1 mark−1/3 if wrong
Consider the following two sets:
Set XSet Y
P. Lexical Analyzer1. Abstract Syntax Tree
Q. Syntax Analyzer2. Token
R. Intermediate Code Generator3. Parse Tree
S. Code Optimizer4. Constant Folding
Which one of the following options is the CORRECT match from Set X to Set Y?
Show answer without attempting

Answer: B

Q11

GATE CS 2023 CSLexical AnalysisMCQ1 mark−1/3 if wrong
Consider the following statements regarding the front-end and back-end of a compiler.
S1: The front-end includes phases that are independent of the target hardware.
S2: The back-end includes phases that are specific to the target hardware.
S3: The back-end includes phases that are specific to the programming language used in the source code.

Identify the CORRECT option.
Show answer without attempting

Answer: B

Q19

GATE CS 2023 CSLexical AnalysisMCQ1 mark−1/3 if wrong
Consider the following definition of a lexical token id for an identifier in a programming language, using extended regular expressions:
<br>letter→[A-Za-z]<br>digit→[0-9]<br>id→letter (letter ∣ digit)∗<br>\begin{align*}<br>\text{letter} & \to \text{[A-Za-z]} \\<br>\text{digit} & \to \text{[0-9]} \\<br>\text{id} & \to \text{letter (letter } | \text{ digit)}^*<br>\end{align*}

Which one of the following Non-deterministic Finite-state Automata with ϵ\epsilon-transitions accepts the set of valid identifiers? (A double-circle denotes a final state)
Show answer without attempting

Answer: C

Q3

GATE CS 2021 CS-2Lexical AnalysisMCQ1 mark−1/3 if wrong
Consider the following ANSI C program:
int main() {
    Integer x;
    return 0;
}
Which one of the following phases in a seven-phase C compiler will throw an error?
Show answer without attempting

Answer: C

Q37

GATE CS 2018 CSLexical AnalysisMCQ2 marks−2/3 if wrong
A lexical analyzer uses the following patterns to recognize three tokens T1,T2T_1, T_2, and T3T_3 over the alphabet {a,b,c}\{a, b, c\}.

T1T_1: a?(b∣c)∗aa? (b|c)^* a
T2T_2: b?(a∣c)∗bb? (a|c)^* b
T3T_3: c?(b∣a)∗cc? (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 bbaacabcbbaacabc is processed by the analyzer, which one of the following is the sequence of tokens it outputs?
Show answer without attempting

Answer: D

Q19

GATE CS 2016 CS-2Lexical AnalysisMCQ1 mark−1/3 if wrong
Match the following:

(P) Lexical analysis --- (i) Leftmost derivation
(Q) Top down parsing --- (ii) Type checking
(R) Semantic analysis --- (iii) Regular expressions
(S) Runtime environments --- (iv) Activation records
Show answer without attempting

Answer: B

Q27

GATE CS 2015 CS-2Lexical AnalysisMCQ1 mark−1/3 if wrong
Match the following:

P. Lexical analysis
Q. Parsing
R. Register allocation
S. Expression evaluation

1. Graph coloring
2. DFA minimization
3. Post-order traversal
4. Production tree
Show answer without attempting

Answer: C

0/90 correct0 marks

Related topics in Compiler Design