Semantic Analysis

From the previous part of the project you learned: 
* 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

In 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.

Symbol Table(s)

You 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 errors.
The data structure of the symbol table is left to your imagination!

The Type System:
The source language contains three predefined types:  integer, string, and boolean, and two predefined type constructors, array and record.

Type equivalence is defined as follows:

Two types named T1 and T2 are equivalent if:
T1 = T2 (i.e. they are the same type name)
or
if T1 was defined as follows
type T1 = T3;
where T2 and T3 are equivalent,
or
if T2 was defined as follows
type T2 = T3;
where T1 and T3 are equivalent.

Two 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.

Implementation of Type Equivalence:

This 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 encounters:
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.

Semantic Analysis

In that part we need to check for the type of errors.

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

Submission rules
  1. The lab submission must be sent as an attachment to an email sent to the TA.
  2. 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.
  3.  Put all your submission files in a directory called "semantic-lastname-firstname"  then tar/zip the whole directory.
  4. Send the tar/zip file as an attachement to the email.