The Gateway to Computer Science Excellence
+3 votes
287 views

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?

in Compiler Design by Boss (25.3k points) | 287 views
0
Lexical analyzer passes the information to next phases to enable error reporting.

1 Answer

+3 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.
by (161 points)
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
50,644 questions
56,517 answers
195,581 comments
101,143 users