2 votes 2 votes checking whether a variable is defined before use is syntax error or semantic error?? Compiler Design compiler-design lexical-analysis + – sudsho asked Oct 3, 2016 • retagged Jun 17, 2022 by Lakshman Bhaiya sudsho 444 views answer comment Share Follow See all 0 reply Please log in or register to add a comment.
4 votes 4 votes Variable declared before use is a semantic error not a syntax error since as we know syntax error just validates the syntax of the statements using the grammar(context free) used for parser. Semantic error deals with the meaning as well . So it constructs annotated parse tree which contains the information about variables used as well.Consider the following C code statements: int x,y; z = x+ y; Both the statements are perfectly fine according to the grammar of parser.But in semantic analysis phase , the compiler comes to know that z is not declared.Hence such error comes under the category of semantic error.If you further query , then plz consult the following link : http://stackoverflow.com/questions/13202808/compiler-design-is-variable-not-declared-a-syntactic-error-or-semantic-error Habibkhan answered Oct 3, 2016 Habibkhan comment Share Follow See 1 comment See all 1 1 comment reply sudsho commented Oct 3, 2016 reply Follow Share means all binding scoping etc are checked during semantic analysis phase?? what will be the errors in syntax analysis phase? like in lexical error we just remove white spaces comments etc and if doesnt matches with identifier expression we gets an error....what are the errors in syntax analysis phase? 0 votes 0 votes Please log in or register to add a comment.