GATE CSE 2018 Q47: Token sequence from longest-match lexer on bbaacabc
- Compiler Design
- 2 marks
- MCQ
- −2/3 if wrong
Syllabus topics: Lexical analysis, parsing and syntax-directed translation; Regular expressions and finite automata
Question
A lexical analyzer uses the following patterns to recognize three tokens , , and over the alphabet .
:
:
:
Note that '' means 0 or 1 occurrence of the symbol . Note also that the analyzer outputs the token that matches the longest possible prefix.
If the string is processed by the analyzer, which one of the following is the sequence of tokens it outputs?
Try it: multiple choice: exactly one correct option
Show answer and explanation
Answer: D (official GATE 2018 final answer key)
Concept used: Maximal munch: at each step the lexer picks the longest prefix of the remaining input that matches any token pattern.
First step: From the start of , find for each pattern the longest prefix it matches (note allows any run of / before a ), pick the longest, and repeat on the rest.
Full step-by-step solution
Loading…
Answer from the official final answer key. Found a mistake? Use Report issue and we will fix it.
More questions on Lexical analysis, parsing and syntax-directed translation
Every PYQ on this topic →Share this question
Source: official GATE 2018 CS question paper and final answer key, organised by IIT Guwahati. Question paper · Answer key
More Compiler Design PYQs
- 2026 Session 1 · Q27Classify errors in three C string declarations
- 2026 Session 1 · Q28True statements about LL(1) parsing
- 2026 Session 1 · Q42Redundant (common) subexpressions in blocks B4 and B5 of a CFG
- 2026 Session 1 · Q53Compare two SDDs for type declarations
- 2026 Session 2 · Q35Count tokens produced by a lexer for a given string
- 2026 Session 2 · Q41Shift-reduce conflicts in the LR(0) table of a grammar