LARA

Identifiers vs Symbols Example

What does this program compute?

class Example {
    boolean x;
    int y;
    int z;
 
    int compute(int x, int y) {
	int z = 3;
	return x + y + z;
    }
    public void main() {
	int res;
	x = true;
	y = 10;
	z = 17;
	res = compute(z, z+1);
	System.out.println(res);
    }
}

In the program above, what are the

identifiers

variables

Scope of a variable = part of program where the variable is visible

What is the scope of each variable?

Can we draw an arrow from occurrence of each identifier to the point of its declaration?

Compilers and interpreters use environments (symbol tables) to keep track of variables in current scope

  • mathematically, these are just partial functions, and we call them maps