Type Rules for the TL07 Language
The formal type rules for TL07 are here,
but the informal rules below should be sufficient for implementing
your type checker for Part #2.
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 index for arrays must be integers.
- The expression guarding IF-statements and WHILE-loops must be boolean.
- If x is an "ARRAY # OF INT;," then
x[<integer expression>] has type INT.
- 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
10/8/07: The informal rules above do not allow assignment to an
element of the the array, which I meant to allow. They do, however,
allow the assignment of one array to another array of the same size,
which I didn't intend to allow. The formal type rules allow both
assignment of array to array and assignment of integer to an element
of an array of integers. Any combination of the above will
be accepted.