retagged by
434 views

1 Answer

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

Related questions

1 votes
1 votes
1 answer
1
ankit_thawal asked Feb 1, 2018
743 views
1. macros are not considered as tokens in tokenizing.2.#include considered as single token2.stdio.h considered as single token. Are the above statements true?
0 votes
0 votes
1 answer
3
Ebrahim asked Jan 12
167 views
Q1. For the following grammar N - AB | BA A - a | CAC B - b | CBC C - a | b Find the FIRST and FOLLOW