How many tokens will be generated by the scanner for the following statement ?…
2014
How many tokens will be generated by the scanner for the following statement ?
x = x ∗ (a + b) – 5;
- A.
12
- B.
11
- C.
10
- D.
07
Attempted by 319 students.
Show answer & explanation
Correct answer: A
Solution:
Tokenize the statement x = x * (a + b) - 5; by listing each identifier, operator, parenthesis, literal, and the semicolon as separate tokens.
identifier 'x'
assignment operator '='
identifier 'x'
multiplication operator '*'
left parenthesis '('
identifier 'a'
plus operator '+'
identifier 'b'
right parenthesis ')'
subtraction operator '-'
numeric literal '5'
semicolon ';'
Total tokens: 12.
Note: Each identifier, operator, parenthesis, literal, and punctuation mark (like the semicolon) is treated as a separate token by a typical scanner.