GATE CSE
First time here? Checkout the FAQ!
x
+4 votes
252 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)   | 252 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 (34.1k 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 Sep 2017
  1. Habibkhan

    7142 Points

  2. Warrior

    2640 Points

  3. Arjun

    2480 Points

  4. rishu_darkshadow

    2466 Points

  5. A_i_$_h

    2214 Points

  6. nikunj

    1980 Points

  7. manu00x

    1846 Points

  8. makhdoom ghaya

    1770 Points

  9. Bikram

    1744 Points

  10. SiddharthMahapatra

    1718 Points


26,133 questions
33,705 answers
79,886 comments
31,105 users