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;

  1. A.

    12

  2. B.

    11

  3. C.

    10

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

  1. identifier 'x'

  2. assignment operator '='

  3. identifier 'x'

  4. multiplication operator '*'

  5. left parenthesis '('

  6. identifier 'a'

  7. plus operator '+'

  8. identifier 'b'

  9. right parenthesis ')'

  10. subtraction operator '-'

  11. numeric literal '5'

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

Explore the full course: Mppsc Assistant Professor