Beyond syntax .
. Example 1
string x;int y;
y = x + 3
the use of x is a type error
. int a, b;
a = b + c
c is not declared
. An identifier may refer to different variables in different parts of the program
. An identifier may be usable in one part of the program but not another
These are a couple of examples which tell us that typically what a compiler has to do beyond syntax analysis.
The third point can be explained like this:
An identifier x can be declared in two separate functions in the program, once of the type int and then of the type char. Hence the same identifier will have to be bound to these two different properties in the two different contexts.
The fourth point can be explained in this manner:
A variable declared within one function cannot be used within the scope of the definition of the other function unless declared there separately. This is just an example. Probably you can think of many more examples in which a variable declared in one scope cannot be used in another scope.
|