GATE CSE
First time here? Checkout the FAQ!
x
+1 vote
281 views
The number of tokens in the following expression is?
+ * * * < = & > { - + + + } ( >> ) + & &
asked in Compiler Design by Boss (6k points)   | 281 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 ago 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 Feb 2017
  1. Arjun

    5278 Points

  2. Bikram

    4230 Points

  3. Habibkhan

    3942 Points

  4. Aboveallplayer

    3086 Points

  5. Debashish Deka

    2378 Points

  6. sriv_shubham

    2308 Points

  7. Smriti012

    2236 Points

  8. Arnabi

    2008 Points

  9. sh!va

    1672 Points

  10. mcjoshi

    1660 Points

Monthly Topper: Rs. 500 gift card

20,856 questions
26,009 answers
59,671 comments
22,107 users