patternMinor
Compiler Design Question
Viewed 0 times
designquestioncompiler
Problem
$\text{Consider the following ANSI C code:}$
$\text{What will be the type of error?}$
$\text{a) Lexical}$,
$\text{b) Syntax}$,
$\text{c) Semantic}$,
$\text{d) None}$ $\tag {GATE-CS 2021}$
According to me, Syntax Analysis phase should detect the error as there is no grammar in C which produces
int main(){
Integer x;
return 0;
}
$\text{What will be the type of error?}$
$\text{a) Lexical}$,
$\text{b) Syntax}$,
$\text{c) Semantic}$,
$\text{d) None}$ $\tag {GATE-CS 2021}$
According to me, Syntax Analysis phase should detect the error as there is no grammar in C which produces
Integer x or in tokenized form id id. Any help is appreciated. :)Solution
Your statement
And you might want to download a copy of the C Standard to check if
Integer x; is syntactically identifier identifier; which is a perfectly fine variable declaration. Semantically, the first identifier must be defined as a type, and the second identifier must not be defined as a variable in the same scope. The first condition fails, therefore ...And you might want to download a copy of the C Standard to check if
int main() is acceptable, or whether it must be int main(void), which is preferable and might be required.Context
StackExchange Computer Science Q#135954, answer score: 4
Revisions (0)
No revisions yet.