GATE CS 2026 Set 2 | Question 35

Compiler Design › Basics & Lexical · NAT · 1 mark · Answer: 13

  1. Question 35Compiler Designnat1 mark
    A lexical analyzer uses the following token definitions
    letter -> [A-Za-z]
    digit  -> [0-9]
    id     -> letter (letter | digit)*
    number -> digit+
    ws     -> (blank | tab | newline)+
    For the string given below,
    x1   23mm  78   y   7z   zz5   14A  8H  AaYcD
    the number of tokens (excluding ) that will be produced by the lexical analyzer is __________. (answer in integer)

    Answer: 13

    Solution

    An id must start with a letter; a number is a run of digits. Scanning (maximal munch): x1→id(1); 23mm→23+mm(2); 78→number(1); y→id(1); 7z→7+z(2); zz5→id(1); 14A→14+A(2); 8H→8+H(2); AaYcD→id(1). Total .

More GATE PYQ on Basics & Lexical

All GATE CS Compiler Design PYQ →

Attempt GATE CS 2026 Set 2 in real GATE exam mode

Full paper with a timer, the GATE interface and a topic-wise analysis — free.

Create free account →