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

Answer should be 17.Arjun sir can u please clarify why we are taking *** as 2 tokens not as 3.

+11 votes

+

*

*

*

< =

&

>

{

-

++

+

}

(

>>

)

+

& &

Totally 17

answered by Veteran (11.5k points)  
& & are two tokens na why did you take it as one token
0 votes
17 tokens in total
answered by (53 points)  


Top Users May 2017
  1. akash.dinkar12

    3154 Points

  2. pawan kumarln

    1636 Points

  3. sh!va

    1590 Points

  4. Arjun

    1350 Points

  5. Bikram

    1298 Points

  6. Devshree Dubey

    1246 Points

  7. Angkit

    1044 Points

  8. Debashish Deka

    1042 Points

  9. LeenSharma

    880 Points

  10. srestha

    706 Points

Monthly Topper: Rs. 500 gift card
Top Users 2017 May 22 - 28
  1. Bikram

    384 Points

  2. pawan kumarln

    262 Points

  3. Ahwan

    236 Points

  4. Arnab Bhadra

    136 Points

  5. LeenSharma

    118 Points


22,770 questions
29,090 answers
65,119 comments
27,635 users