in Compiler Design edited by
3,739 views
10 votes
10 votes
When do we count ++(post increment or pre increment) as 1 or 2 token ?
in Compiler Design edited by
3.7k views

3 Comments

All operators are tokens, hence ++ is taken as a single token.

Correct if wrong.
0
0

This will be consider as single token, because compiler apply greedy approach for performing tokenization, it will try to include more character in token if possible.

https://gcc.gnu.org/onlinedocs/cpp/Tokenization.html

6
6

@ Shubhanshu Thanks it helps :) /\

0
0

3 Answers

8 votes
8 votes
Best answer
Preprocessor follows greedy approach to tokenize,  This can be done in TWO steps

1 => Separated by space (A+ ++B) => Have 4 tokens(Space is not considered as token), here tokens are A, +, ++, B(In order of expression). If any operator doesn't have any space ,

then ,

2 => Greedy approach (A+++B) for longest possible valid operator in the Grammer => Like we have '++' > '+' so here the tokens are A,++, +, B(In order of expression).
selected by

4 Comments

a will be 1 token

+= will be another

b be will another

so total will be 3 tokens.
0
0
Pre processor or Lexical Analyzer?
0
0

4 tokens a,+=,b,;.

 

0
0
5 votes
5 votes
Always when we count the token complier always see next symbol

Eg-

++= 1token

a+++++b =5tokens

&&= 1token
edited by
0 votes
0 votes
I think 2 tokens because count is an identifier and ++ is an operator.

Related questions