Familiarisation with Semant package | |
Environments | |
Scope Checking | |
Type Checking | |
Note – these slides are available on the web |
Building the Contextual Analyser
New directories/files: copy into your existing compiler | ||
cp –r $Tiger/Tiger/chap5/Semant . | ||
cp –r $Tiger/Tiger/chap5/Types . | ||
cp –r $Tiger/Tiger/chap5/Translate . | ||
cp –r $Tiger/Tiger/chap5/Absyn/* Absyn | ||
cp –r $Tiger/Tiger/chap5/tests . | ||
Compile ordering | ||
all in Types all in Translate | ||
Semant/Entry.java Semant/FunEntry.java | ||
Absyn/FunctionDec.java Absyn/TypeDec.java | ||
Semant/VarEntry.java Absyn/VarDec.java | ||
Semant/Print.java Absyn/Exp.java | ||
all in Semant all in Absyn |
Run compiler with: java Semant.Main <program> | |||
Examine Semant/Env.java | |||
Notice the 2 tables for the 2 environments | |||
Examine, then compile tests/1.tig | |||
Find the code that is reporting the error – work out what it’s doing | |||
Make the two types have different names | |||
Does that fix it? | |||
What does this tell you about type and variable names? |
Most of the CA operations in here | |||
Examine analysis of a while loop | |||
Is it ok? Write a program to check… | |||
Compare with analysis of if statement | |||
Examine function call | |||
Notice that no checking is taking place at all | |||
Write a checker for this | |||
Hint – notice the recursive nature of the formal and actual parameter lists – use a recursive fn here? |
Write a small program to check if these work properly | ||
If not | ||
Examine the code for function declarations | ||
Correct it |
I’ve removed one check from the contextual analyser phase | ||
(apart from those covered in this session) | ||
Find it for a prize… | ||
I suggest working as a team | ||
Split up the language between you | ||
Use test cases & code inspection? |