From the previous part of the project you
* How to include semantic actions into production rules
* What is the order by which production rules are accessed .
* How to build a very simple symbol table
this part of the project we will build a more realistic symbol table,
and use it for semantic analysis and type checking.
You will just need to continue on the
parser file you have
built in the previous part of this project.
must have a symbol table per scope ( procedure call for simplicitcy in
this project), like Figure 2.36 in the textbook. The entry of
each symbol table contains the lexeme of the identifier, its type, etc.
This hierarchy of symbol tables allows you to catch several semantic
The data structure of the symbol table is left to your imagination!
The source language contains three predefined types: integer, string,
and two predefined type constructors, array and record.
is defined as follows:
Two types named T1 and T2 are equivalent if:
T1 = T2 (i.e. they are the
same type name)
if T1 was defined as follows
type T1 = T3;
where T2 and T3 are equivalent,
if T2 was defined as follows
type T2 = T3;
where T1 and T3 are equivalent.
anonymous types are equivalent if they are constructed from the same
type constructors and their components are equivalent. For records,
this means that
the names and order of the fields must be identical
and their corresponding types must be equivalent. For arrays, the
bounds must be identical and the element
types must be equivalent.
Notice that some new entries must be entered in the symbol table before
compilation begins, namely the entries for integer, string, boolean, true,
false, and other predefined identifiers.
of Type Equivalence:
kind of equivalence is easy to implement. If, in your symbol table, the
symbol A simply points to a type descriptor, then if your type checker
type B = A;
It can install B into the symbol table, pointing to the same type
descriptor as A.
Using this type system, you can catch semantic errors where two
idenfiers are of unequivalent types.
In that part we need to check for the type of errors.
- Any used variable must have been declared first in its
- Catch multiple declarations of the same variable within the
unequivalent types. For simplicity, we all assume that this error
happens whenever A = B occurs and both A and B are of different types.
Note that sometimes different types do not mean an error as they can be
changed through coersion or casting. But we are not considering this
Your compiler must output error messages for each error
encountered specifying the type of error (no need to mention location
information such as line number).We will test this part of your project
with a program that contains only semantic errors indicated above (i.e.
no syntactic or lexical errors).
What you have to submit
All source files for flex, bison, and any
external source code you have.
Readme indicating how to compile and run your program
- The lab submission must be sent as an attachment to an email sent
to the TA.
- Subject: of the email must be
Compiler-Semantic-lastname-firstname, lastname is your last name in lower case and firstname is your first
name in lower case.
- Put all your submission files in a directory called "semantic-lastname-firstname" then tar/zip the whole directory.
- Send the tar/zip file as an attachement to the email.