Question:

A lexical analyser processes the input string int x = a + 10; How many tokens are generated?

Show Hint

White spaces and comments are ignored by the lexical analyser and are not counted as tokens. They merely act as "delimiters" to help separate the actual tokens.
Updated On: Jul 4, 2026
  • 5
  • 6
  • 7
  • 8
Show Solution
collegedunia
Verified By Collegedunia

The Correct Option is C

Solution and Explanation

Concept: A Lexical Analyser (Scanner) breaks the source code into the smallest meaningful units called "Tokens."
Keywords: Reserved words like int, while, return.
Identifiers: Names of variables or functions (e.g., x, a).
Operators: Symbols like =, +.
Constants/Literals: Numeric values like 10.
Punctuators: Separators like ;.

Step 1:
Scanning the input string.
The string is: int x = a + 10;

Step 2:
Identifying each token.

{int (Keyword)
{x (Identifier)
{= (Assignment Operator)
{a (Identifier)
{+ (Arithmetic Operator)
{10 (Constant/Literal)
{; (Separator/Punctuator)

Step 3:
Calculating the total count.
Total tokens = 1 (int) + 1 (x) + 1 (=) + 1 (a) + 1 (+) + 1 (10) + 1 (;) Total = 7 tokens.
Was this answer helpful?
0
0