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_____________.

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โ€ฆ

Attempted by 36 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

Loading lessonโ€ฆ