Log In
4 votes


in Compiler Design 1.1k views
Please explain when Lexical error generates and when Syntax error generates i usually get confuse in between both :(
Ok brother so only in these 6 types lrxical error occurs ?

Shaik Masthan bro can you please post all images for lexical, syntax, symentaic error conditions if you have in your notes

Yeah brother that would be really helpful

4 Answers

5 votes

int a b;= long identifier it can detect during lexical analysis

int 1ab2;=I'll formed numeric literal it can detect during lexical analysis

in t a b;= long identifier it can detect during lexical analysis

D) All the above

3 votes
C will be right option

<1ab2> is invalid token as it is neither keyword nor can be an identifier as 1st  character is a number.
0 votes

All of them are Lexical Errors. Lexical analysis is implemented using Finite Automata.  

Option A: int a b;
Start->int->a->"Expected either ; or = but got whitespace." (Error) Generated Tokens: 2

Option B: in t a b;
Start->i->n->"Expected t but got whitespace" (Error) Generated Tokens: 0

Option C: int 1ab2;
Start->int->"Expected a permitted character but got 1"->a "Didn't expect a character after a number" (Error) Generated Tokens: 1

Explanation of Option C: A parser doesn't support Backtracking. After getting 1 (Which was not permitted) the compiler got a which means that it has to backtrack.


0 votes
Option D ) All of the above.

Related questions

9 votes
4 answers
int main() { int 1a, b; Printf("\nGate 2018"); Printf("%d",x); } How many types of error are there in this code?
asked Jan 31, 2018 in Compiler Design Shubhanshu 2.5k views
5 votes
4 answers
if there is miss spelling in some keyword in a program then this misspelled keyword will be treated as lexical errors or it will be treated as a new identifier and accepted as a token ?? ex - whiel (1) ; here while is misspelled as whiel
asked Nov 2, 2017 in Compiler Design itsvkp1 1.3k views
2 votes
1 answer
This screenshot is token from the book Ullman, How can following be a lexical error? because "elipseSize" should have a token recorded as an identifier.
asked Sep 26, 2017 in Compiler Design Manu Thakur 776 views
5 votes
3 answers