in Compiler Design
577 views
1 vote
1 vote

What is the earliest stage compiler error for the following C code snippet:

int x = @33;
  1. Lexical Error
  2. Syntax Error
  3. Semantic Error
  4. None
in Compiler Design
577 views

1 comment

The lexical analyser will catch this error

as we know in any valid assignment numbers must belong to (0-9), @ is an illegal character

Read more from here : https://www.geeksforgeeks.org/lexical-error/

1
1

2 Answers

3 votes
3 votes
Best answer

Answer: Option A) Lexical Error

The compiler will show a lexical error because of the "@" symbol in $@33$. It is not a valid character for variable assignment in the C programming language.  An identifier can only have alphanumeric characters (a-z , A-Z , 0-9) (i.e. letters and digits) and underscore $(\_)$ symbol.

selected by

3 Comments

Thanks,
Just to comfirm "int a = Y34_" lexical won't catch this right?

1
1

@Souvik33 Yes, it will not generate lexical error because the variable name "Y34_" is a valid token. It will be raised as a semantic error

1
1
1
1
1 vote
1 vote
The earliest stage compiler error for the given C code snippet is a lexical error. This is because @ is not a valid token in the C language, so the compiler would detect it as a lexical error at the very beginning of the compilation process.

Related questions