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?

| 287 views
0
Lexical analyzer passes the information to next phases to enable error reporting.

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)