raphnguyen
raphnguyen

Reputation: 3605

C Counting Tokens

In each of the following statements, what are the tokens?

a. x = y +++ 3;
x, =, y, ++, +, 3, ; 7 tokens
b. a+=c*=(d+-2)>>5&3;
a, +=, c, *=, (, d, +, -, 2, ), >>, 5, &, 3, ; 15 tokens

For each, state whether it is a syntactically correct expression.

a. x+++y
x, ++, +, y. Yes.
b. x+++++y
x, ++, ++, +, y. No.

Just wondering if I'm counting tokens the right way. I wasn't sure if parenthesis are counted as separate tokens or not.

Upvotes: 1

Views: 246

Answers (1)

caf
caf

Reputation: 239071

Yes, your proposed answers are correct. Parentheses are tokens - in the C grammer, they're one of a class of tokens called punctuators.

Upvotes: 3

Related Questions