GATE / CS ARCHIVE

GATE CSE 1995 / QUESTION 1.13

Recognizing a Pascal token without lookahead

Compiler Design · Lexical Analysis · Full GATE CSE 1995 paper

GATE 1995, Q1.13 1 mark · MCQ
Report issue

Lexical Analysis

Question 1.13, GATE 1995: Which can definitely be recognized as a whole token without reading the next character: I begin, II program, III <>?
Tap to enlarge
Your answer
Answer & solution

Answer: C: III (no official key was published)

The characters begin may be followed by another identifier character, producing an identifier such as beginning rather than the keyword begin. The same issue applies to program. The lexer therefore needs to determine the word boundary before deciding those tokens. Pascal’s <> is a complete relational operator with no longer operator having it as a prefix, so it can be recognized immediately after the second character. This is the longest-token principle, not a claim that keywords cannot ever be recognized.

Original paper, page 2