GATE CSE
First time here? Checkout the FAQ!
x
+4 votes
199 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)   | 199 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

+8 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 (33.9k 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 May 2017
  1. akash.dinkar12

    3338 Points

  2. pawan kumarln

    2108 Points

  3. Bikram

    1922 Points

  4. sh!va

    1682 Points

  5. Arjun

    1614 Points

  6. Devshree Dubey

    1272 Points

  7. Debashish Deka

    1208 Points

  8. Angkit

    1056 Points

  9. LeenSharma

    1018 Points

  10. Arnab Bhadra

    812 Points

Monthly Topper: Rs. 500 gift card
Top Users 2017 May 22 - 28
  1. Bikram

    1008 Points

  2. pawan kumarln

    734 Points

  3. Arnab Bhadra

    726 Points

  4. Arjun

    342 Points

  5. bharti

    328 Points


22,893 questions
29,196 answers
65,302 comments
27,695 users