GATE CSE
First time here? Checkout the FAQ!
x
+1 vote
291 views
The number of tokens in the following expression is?
+ * * * < = & > { - + + + } ( >> ) + & &
asked in Compiler Design by Boss (6k points)   | 291 views
As ++ is used to increment the value we are taking it as single token. But In this case * is used as  multiplication operation.That's why 3 separate tokens. Am I right?

3 Answers

–1 vote
Best answer

Ans is 16..

+

**

*

< =

&

>

{

-

++

+

}

(

>>

)

+

& &

 

I think longest match rule is applied.

answered by Boss (6k points)  
selected by
AFAIK It should be 17

@vaishali 

** is not defined in C....they are 2 separate tokens

I have a doubt. Can't we just divide "<=" to "<" and "="  as separate tokens?

u can divide...but lexical analyser will not..it follows longest matching rule...

If it was C++, then ++ will be counted as signle token?
@sh!va yes...we pre define the regular expressions for lexical analyser based on our compiler..if it's C or C++ then all identifiers,keywords etc will be treated the same and tokens will be generated regarding them...since ++ is define in C it will be treated as single token following longest match...but +++ will be treated like ++ as one token and next + as one token..

longest match rule

if i wanna try to search your name

 

i will type m & ot wills how all names start with m

 

then i type ma then iw ill show name starts wil ma

 

so it goes & finally i will type marco and it will show name with marco.

 

so it will not show other m name which does not have arco after . so longest match.

 

same happens with destination network address matching of a packet with network address of routes in routing table.

+10 votes

+

*

*

*

< =

&

>

{

-

++

+

}

(

>>

)

+

& &

Totally 17

answered by Veteran (11.4k points)  
0 votes
17 tokens in total
answered by (53 points)  


Top Users Mar 2017
  1. rude

    4018 Points

  2. sh!va

    2994 Points

  3. Rahul Jain25

    2804 Points

  4. Kapil

    2608 Points

  5. Debashish Deka

    2104 Points

  6. 2018

    1414 Points

  7. Vignesh Sekar

    1336 Points

  8. Bikram

    1218 Points

  9. Akriti sood

    1186 Points

  10. Sanjay Sharma

    1016 Points

Monthly Topper: Rs. 500 gift card

21,446 questions
26,759 answers
60,943 comments
22,955 users