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

2 Answers

+9 votes
Best answer

+

*

*

*

< =

&

>

{

-

++

+

}

(

>>

)

+

& &

Totally 17

answered by Veteran (10.4k points)  
selected by

Ans is 16..

+

**

*

< =

&

>

{

-

++

+

}

(

>>

)

+

& &

 

I think longest match rule is applied.

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.

0 votes
17 tokens in total
answered by (53 points)  
Top Users Jan 2017
  1. Debashish Deka

    8968 Points

  2. sudsho

    5326 Points

  3. Habibkhan

    4798 Points

  4. Bikram

    4532 Points

  5. Vijay Thakur

    4486 Points

  6. saurabh rai

    4222 Points

  7. Arjun

    4196 Points

  8. santhoshdevulapally

    3808 Points

  9. Sushant Gokhale

    3596 Points

  10. Kapil

    3486 Points

Monthly Topper: Rs. 500 gift card

19,212 questions
24,104 answers
53,151 comments
20,319 users