GATE CSE
First time here? Checkout the FAQ!
x
+4 votes
186 views
a = 1+1+1+ 1+1+1 1+1;

as far as i think, it will pass the lexical phase.. it should b syntax error.. correct ??
asked in Compiler Design by (89 points)   | 186 views
yes.. All are valid tokens.
Tokens r valid, but d code will not compile. I think d error will b in syntax analyzer phase.. No grammar will b available to construct parse tree of given string.

2 Answers

+7 votes
Best answer

Yes, It will pass the lexical phase. 

There is a specific rule in "integer constant creation" that you can not have a blank space between a number.

In the above line after 5th 1, "1 1", cause an error.  This error is a grammatical error. Hence It will be not pass syntax analysis. Hence syntax error will be generated and reported at compile time. 

answered by Veteran (30.6k points)  
selected by
In Lexical analysis phase, it removes all the white spaces and comments. so white space between 1 should also be removed, also LA phase makes use of Regular expressions to identify tokens, so it makes sense what you are saying.

Still confusing.

I think there are conflicts between answers. If there is any example of such question over internet or any other text book you guys know, then please do share.

Thanks.

There is a specific rule in "integer constant creation" that you can not have a blank space between a number

https://gcc.gnu.org/onlinedocs/cpp/Tokenization.html

 

Thanks.. this solved the confusion.
@Arjun Sir, Is my answer is not correct? Why did I get a down vote for this? :( :(
yes, its not correct. 1 1 should be two valid tokens in C.
@Arjun sir, yeah i got my mistake. Now I have edited it. I think now its correct. Thx.
+1 vote
Yes , this error will be generated at the time of syntax analyzer . you cant make a parse tree for this
answered by (23 points)  

Related questions

0 votes
2 answers
1
asked in Compiler Design by prasitamukherjee Loyal (3.8k points)   | 276 views
+1 vote
2 answers
3


Top Users Mar 2017
  1. rude

    5236 Points

  2. sh!va

    3054 Points

  3. Rahul Jain25

    2920 Points

  4. Kapil

    2732 Points

  5. Debashish Deka

    2602 Points

  6. 2018

    1574 Points

  7. Vignesh Sekar

    1430 Points

  8. Bikram

    1424 Points

  9. Akriti sood

    1420 Points

  10. Sanjay Sharma

    1128 Points

Monthly Topper: Rs. 500 gift card

21,549 questions
26,889 answers
61,248 comments
23,251 users