GATE CSE
First time here? Checkout the FAQ!
x
+4 votes
166 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)   | 166 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.3k 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 Jan 2017
  1. Debashish Deka

    7172 Points

  2. Habibkhan

    4696 Points

  3. Vijay Thakur

    4308 Points

  4. sudsho

    4090 Points

  5. saurabh rai

    4024 Points

  6. Arjun

    3292 Points

  7. santhoshdevulapally

    3066 Points

  8. GateSet

    3016 Points

  9. Bikram

    3014 Points

  10. Sushant Gokhale

    2892 Points

Monthly Topper: Rs. 500 gift card

18,838 questions
23,808 answers
51,589 comments
20,148 users