720 views
4 votes
4 votes

int main()
{
    print("%d",a);
    return 0;
}

If i execute,i will get error as:- 

prog.c:112:17: error: 'a' undeclared (first use in this function)
     printf("%d",a);

Now as this is the semantic error,so how does semantic analyzer knows the row and column number while printing error?

I know lexical analyzer can give the row number and column number of error as it tokenize the entire program but is this also possible in sematic analyzer?

1 Answer

4 votes
4 votes
Let me remind you, all these information is stored in symbol table which used across the compilation process. Lexical analyzer tokenize and store line number information in ST, which further used and can be modified by sematic analyzer.

BTW, good oberservation.

Related questions

2 votes
2 votes
4 answers
3