Semantic Analysis
Environments
 Symbol Tables
Scope Checking
Type Checking
Translate program rep. again...

Environments
Every expression evaluated in the context of an environment
An environment consists of bindings
mapping identifiers to meanings
In typical PLs
a declaration adds a binding to the environment
exiting a scope removes bindings

Multiple environments
Many languages support multiple, simultaneously-active, environments
Each Java class introduces an environment
Each Ada package also
… and also each function and its parameters
in Tiger
Environment for variables and functions
Environment for type names

Symbol Tables
Mechanism used to implement environments
Functional style tables
Imperative style tables

In Tiger
public class Table {
public Table();
public void put( Symbol key,
  Object value );
public Object get( Symbol key );
public void beginScope();
public void endScope();
}

What is in each binding?
Types
Variables
Functions

Type checking expressions
Recursive traversal of the AST
E.g. for a simple addition expression

What to do on….?
variable use
array subscript
record field access
variable declaration
function declaration
type declaration

And recursive types / functions?
Do not know type declared ahead…
… or function name or arg types if declared ahead

Finally
Read through Chapter 5
expands on what I discussed here
Work out where/how the scope checking will work...