Type Rules for the TL09 Language
Informal Type Rules
- The operands of all OP2, OP3, and OP4 operators must be integers
- The OP2 and OP3 operators create an integer result.
- The OP4 operators create boolean results.
- All variables must be declared with a particular type.
- The left-hand of assignment must be a variable, and the right-hand
side must be an expression of the variable's type.
- When used as a value, a variable's type is its declared type.
- Only integer variables may be assigned the result of READINT.
- WRITEINT's expression must evaluate to an integer.
- The expression guarding IF-statements and WHILE-loops must be boolean.
- The literals "FALSE" and "TRUE" are boolean constants.
- The literal numbers -2147483648 through 2147483647 are integer
constants. Numbers outside of that range should be flagged as
illegal.
Errata/Clarifications
- 2009/10/12:
These rules do not say anything about what to do if the same
variable is declared multiple times. Let's consider this a type
error such that the second declaration (and perhaps the variable
in the second declaration) should be marked as a type error (i.e.,
"pastel13/1"). The rest of the AST may be annotated with x being
assumed to be either the original type (INT) or the new type (BOOL).