The Gateway to Computer Science Excellence
+3 votes

int main()
    return 0;

If i execute,i will get error as:- 

prog.c:112:17: error: 'a' undeclared (first use in this function)

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?

in Compiler Design by | 323 views
Lexical analyzer passes the information to next phases to enable error reporting.

1 Answer

+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.
Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
52,375 questions
60,574 answers
95,389 users