• retagged by
5,407 views
6 6 votes

 

7 Answers

5 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

4 4 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.
2 2 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 0 votes
OPTION C, is the answer.

Because an identifier must always start with an underscore or a letter. Since  (1ab2) starts with a number, it obviously gives a lexical error.

Other explaination:

Since OPTION A is correct, A and D are ruled out.

and in OPTION B, (in t a b;), we get 5 tokens.
0 0 votes
  • Lexical : name of some identifier typed incorrectly

  • Syntactical : missing semicolon or unbalanced parenthesis

  • Semantical : incompatible value assignment

  • Logical : code not reachable, infinite loop

Position:
Show:

Related questions

0 0 votes
1 1 answer
2.6k
2.6k views
Mohit Aggarwal asked Dec 1, 2021
2,601 views
what is the difference between lexical error and syntax error?
11 11 votes
6 6 answers
12.4k
12.4k views
Shubhanshu asked Jan 31, 2018
12,424 views
int main() { int 1a, b; Printf("\nGate 2018"); Printf("%d",x); }How many types of error are there in this code?
1 1 vote
3 3 answers
3.0k
3.0k views
shikharV asked Nov 19, 2015
3,048 views
Given answer: DPlease explain