6 6 votes Consider the following C program : ``` # include main() I int }x=10,y=12 char * a; a=&a; x = 1xab; printf ("%d %d", x, * a); } ``` Which of the following type of error (earliest phase) is identified during compilation of the program ? a. Lexical error b. Syntax error c. $\AA$ Semantic error d. None of these Attempt Incorrect Your Ans. Correct Ans. a Compiler Design compiler-design lexical-analysis test-series + – prasitamukherjee 8.4k views answer comment Share Follow Print See all 5 Comments 5 5 Comments reply Show 2 previous comments Hradesh patel commented Dec 27, 2016 reply Follow flag @sudso .......plz give any refernce..... 0 0 replyShare MIRIYALA JEEVAN KUMA commented Jan 31, 2018 i edited by MIRIYALA JEEVAN KUMA Jan 31, 2018 reply Follow flag i think its not a lexical error 1 -- > token (integer constant) xab --> token (identifier) this is the output screen shot on gcc compiler 0 0 replyShare MIRIYALA JEEVAN KUMA commented Jan 31, 2018 reply Follow flag #include<stdio.h> int main() { int +-; } Here for this programm you may say that "+-" gives lexical error but it does not here is output screenshot here + is identified as token 1 1 replyShare Please log in or register to add a comment.
Best answer 22 22 votes 1xab - is not a valid token in C (as variable names cannot start with a digit and numbers cannot have a letter other than 'x' (for hex) or 'l' (for long) and also not a valid keyword) and hence lexical error. It could have been x1ab, _x1ab etc. both would have given a semantic error for variable not defined. Arjun answered Dec 14, 2016 • selected Dec 18, 2016 by prasitamukherjee Arjun comment Share Follow See all 16 Comments 16 16 Comments reply Show 13 previous comments tp21 commented Sep 29, 2019 reply Follow flag Thank you Sir for your comment. Is my below assumption correct? Token separators are: 1)whitespaces 2)operators 3) special symbols like ( ) , { } " : And also are there more valid token separators apart from this? 0 0 replyShare tp21 commented Sep 29, 2019 reply Follow flag And also here https://gateoverflow.in/204111/gate2018-37 We didn't considered token separator concept here.why so? Is this because in gcc, FA considers token separator to distinguish between tokens. And here this question has given its own token pattern which does not considers token separator. 0 0 replyShare `JEET commented Sep 29, 2019 reply Follow flag First of all that is invalid, right? @tp21 You can't have a lexeme pattern like that. So, I think the discussion ends there itself? 0 0 replyShare Please log in or register to add a comment.
3 3 votes It is a lexical error at earliest as we can see that the token "1xab" will be treated as an identifier ..But we know as per standard naming convention in C language , the variable name cannot begin with "1" .. So it will be an invalid token..Hence the error concerned will be lexical error at the earliest.. Hence A) is correct answer.. Habibkhan answered Dec 27, 2016 Habibkhan comment Share Follow See all 4 Comments 4 4 Comments reply Hradesh patel commented Dec 27, 2016 reply Follow flag if digit in anywhere other than starting then its valid or not?? 0 0 replyShare Habibkhan commented Dec 27, 2016 reply Follow flag It is valid in all other cases except beginning 0 0 replyShare Vishal Goyal commented Apr 11, 2017 reply Follow flag Undeclared variable is syntax or Symantic error 0 0 replyShare Verma Ashish commented Dec 28, 2018 reply Follow flag Undeclared variable is not a syntax error.. https://gateoverflow.in/262335/number-of-tokens 0 0 replyShare Please log in or register to add a comment.
0 0 votes Lexical analyser scan the program and generate token store into symbol table and return token id. Token may be Keyword Identifier(function or variable) Operators Special symbols. So 1xba not any things So it produces Lexical error Gautam Pandey answered Jun 20, 2017 Gautam Pandey comment Share Follow 0 reply Please log in or register to add a comment.