Calculating tokens in c statement

As far as I understand C code parsing, the tokens are (10 in total):

printf
(
"i = %d, &i = %x"
,
i
,
&
i
)
;

I don't count white space, it's generally meaningless and only serves as a separator between other tokens, and I don't break down the string literal into pieces, because it's an integral entity of its own.


This looks very much like a school assignment or something, but depending on whether or not whitespace counts: 10 or 12 (or 13, if whitespace counts and there is an ending newline)

'printf' '(' '"i = %d, &i = %x"' ',' 'i' ',' '&' 'i' ')' ';'
  1       2     3                4   5   6   7   8   9  10

yes totally 10 tokens.Because the characters which are represented in quotes can be treated as single token by the lexical analyser(LA).that is the property of LA.

Tags:

C

Token