in Compiler Design retagged by
18,486 views
6 votes
6 votes

Given solution:

Please explain how the number of tokens are 11.

in Compiler Design retagged by
18.5k views

3 Answers

22 votes
22 votes
Best answer
Actually there are 12 tokens.
they Left semi colon (;)  ..
selected by

3 Comments

Consider a multi line comment code like below:
 


foo/*blah blah blah....
blah....blah...*/10;

how many tokens I should count in this code section 3 or 2?

0
0
3

1st  Token   foo

2nd Token   10

3rd Token   ;
1
1

Comments are ignored whether single line or multi-line.

Newline character, spaces, tabs are also ignored.

So, 3 tokens:

foo

10

;

0
0
11 votes
11 votes
We may a have a confusion of slecting && a single token or & as 2 diff token

Similarly the same thing goes for + or ++

The concept that come "MAximal match ".If you have + and may with one look ahead you have encountered ++ then in that case you will take maximal one . ie ++ so it would be considered ++ as token under relational operator token class

similarly a & is address operator and && is a logical so you take max of both of them so its &&

Now but in case of *** you cant have "all" of them as a single token . or we dont have any opearator (***) -we are extending the indirection property .There is no such token class , Infact each of * will come under one token class . SO all 3 in one token class

So the token are printf

c

"what up %id "

,

++

&&

*

*

*

a

)

;

ALl of these counts to 12 ! :)

2 Comments

in case  c+a+b++  will count as 6 token
0
0
Yes it would be 6 token

c

+

a

+

b

++
1
1
4 votes
4 votes

/* abc*/ gives 0 token bcz lexical analyzer avoid the comment 

printf count as 1 token

(   count as 1 token

"whats up %d" count as 1 token

 ,count as 1 token

++ is increment operator so count as 1

&& is also logical AND operator so count as 1

*** are count as 3 token

a     count as 1 token 

) count as 1 token 

; count as 1 token so 

tatal 12 token plz correct me if i am wrong

by
Answer:

Related questions