A lexical analyzer uses the following token definitions: For the string given…

2026

A lexical analyzer uses the following token definitions:

image.png

For the string given below,

π‘₯1 23π‘šπ‘š 78 𝑦 7𝑧 𝑧𝑧5 14𝐴 8𝐻 π΄π‘Žπ‘Œπ‘π·

the number of tokens (excluding 𝑀𝑠) that will be produced by the lexical analyzer is_____________.

Attempted by 18 students.

Show answer & explanation

Correct answer: 13

To find the number of tokens, we parse the input string from left to right using the given grammar rules.
Rules: id starts with a letter, number starts with a digit.
x1 -> id
23 -> number
mm -> id
78 -> number
y -> id
7 -> number
z -> id
zz5 -> id
14 -> number
A -> id
8 -> number
H -> id
AaYcD -> id
Total number of tokens = 13.

A video solution is available for this question β€” log in and enroll to watch it.

Explore the full course: Gate Guidance By Sanchit Sir