Type

Due: Apr 10, 11:59pm
Submit Project: type 
Test Files:  t2.txt t3.txt t4.txt max.txt maxErr.txt fact.txt factErr.txt


Results:     t2.out t3.out t4.out max.out maxErr.out fact.out factErr.out

In this project, you are asked to implement a static type checker for Gee language. The type rules of Gee are the same as those of CLite, except for the following:

  1. Gee programs do not need explicit variable declarations.
  2. The values in the test programs contain only number and boolean types of values. No need to consider string or other types.
  3. No test case or assignment will contain the boolean constants True, False. For example, the following kinds of statements won't appear in the test files: v = True; if (x==False). But the following could: v = (x> 0); if (x>y).
  4. No implicit type convertions are allowed. So the types of the operands of a binary operator (including the assignment operator) must match with each other.

You are allowed to develop it based on either your parser developed in the previous project or the paser sent to you by the grader. (The semantic part of the parser is not relevant to this project.)

Use tipe as the name of the type function of each class.

The type map described in class can be modeled using a Python dictionary (associative array). This dictionary, named tm, should be explicitly passed as an argument to each tipe function.

The order in the output does not matter as long as the error message, if there is any, is printed as the final line.

Remember: the tipe function of an expression should not only check the type validity of the expression, but also return the type of the result of the expression.

Hint: Invoke the type checker after the program parsing has finished.