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

+13 votes

+

*

*

*

< =

&

>

{

-

++

+

}

(

>>

)

+

& &

Totally 17

answered by Veteran (12.5k points) 10 47 90
& & are two tokens na why did you take it as one token

We have taken && as one token because it stands for logical AND in C.

0 votes
17 tokens in total
answered by (63 points) 1 2
–1 vote

Ans is 16..

+

**

*

< =

&

>

{

-

++

+

}

(

>>

)

+

& &

 

I think longest match rule is applied.

answered by Boss (6.5k points) 8 115 247
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.



Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
Top Users Oct 2017
  1. Arjun

    23338 Points

  2. Bikram

    17048 Points

  3. Habibkhan

    7912 Points

  4. srestha

    6228 Points

  5. Debashish Deka

    5438 Points

  6. jothee

    4968 Points

  7. Sachin Mittal 1

    4772 Points

  8. joshi_nitish

    4286 Points

  9. sushmita

    3964 Points

  10. Rishi yadav

    3794 Points


Recent Badges

Popular Question makhdoom ghaya
Popular Question junaid ahmad
Notable Question learner_geek
Notable Question jothee
Popular Question jothee
Notable Question Jeffrey Jose
Notable Question air1ankit
Nice Question jothee
Verified Human shaleen25
Popular Question jothee
27,290 questions
35,142 answers
83,920 comments
33,231 users