| Environments | ||
| Symbol Tables | ||
| Scope Checking | ||
| Type Checking | ||
| Translate program rep. again... | ||
| 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 | ||
| 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 | ||
| Mechanism used to implement environments | |
| Functional style tables | |
| Imperative style tables |
| public class Table { | |
| public Table(); | |
| public void put( Symbol key, | |
| Object value ); | |
| public Object get( Symbol key ); | |
| public void beginScope(); | |
| public void endScope(); | |
| } |
| Types | |
| Variables | |
| Functions |
| Recursive traversal of the AST | |
| E.g. for a simple addition expression |
| 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 | |
| Read through Chapter 5 | ||
| expands on what I discussed here | ||
| Work out where/how the scope checking will work... | ||