GATE CSE
First time here? Checkout the FAQ!
x
+4 votes
177 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)   | 177 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 (25.4k 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)  
Top Users Feb 2017
  1. Arjun

    5386 Points

  2. Bikram

    4230 Points

  3. Habibkhan

    3952 Points

  4. Aboveallplayer

    3086 Points

  5. Debashish Deka

    2564 Points

  6. sriv_shubham

    2318 Points

  7. Smriti012

    2240 Points

  8. Arnabi

    2008 Points

  9. mcjoshi

    1696 Points

  10. sh!va

    1684 Points

Monthly Topper: Rs. 500 gift card

20,863 questions
26,022 answers
59,696 comments
22,133 users