Informal Semantics for the TL07 Language
- Only those variables which have been declared can be assigned
to or used.
- All INT variables and array elements are considered to have
initial values of "0".
- All BOOL variables are considered to have initial values of "false".
- All binary operators operate on signed integer operands:
- "x * y" results in the product of x and y.
- "x / y" which results in the integer quotient of x divided by y
- "x % y" is the results in the remainder of x divided by y.
(such that if r = x % y; and q = x / y, then x = y * q + r,
|r| < |y| and the sign of r is the sign of x.)
- "x + y" results in the sum of x and y.
- "x - y" is the difference of y subtracted from x.
- "x == y" is true if x and y are the same, otherwise it is false.
- "x != y" is false if x and y are the same, otherwise it is true.
- "x < y" is true if x is less than y, otherwise it is false.
- "x > y" is true if x is greater than y, otherwise it is false.
- "x <= y" is true if x is less than or equal to y, otherwise it is false.
- "x >= y" is true if x is greater than or equal to y, otherwise it is false.
- An assignment updates the current value of the variable or array element
denoted by its left-hand side to be the value resulting from evaluating
the right-hand side.
- IF statements evaluate their expression, if the expression is true,
then the "then-statements" are executed, if it is fales, the
"else-statements" are executed.
- WHILE statements first evaulates its expression. If it is false,
execution continues after the end of the WHILE statement. If
it is true, the statements in the body of the WHILE loop are
executed. After they finish executing, the expression is
re-evaluated. As long as the expression is true, the process
repeats itself, alternatively evaluating the expression and
executing the statements in the body. Once the expression is false,
execution continues after the end of the WHILE loop.
- WRITEINT evaluates its expression and outputs the result to the console
and causes the cursor to move to the beginning of the next line.
- READINT reads an integer from the console and updates an integer
variable to hold that value.
- Array indices are 0-based.
If, at runtime, a statement's index expression of a variable is is not a
non-negative number less than the bound specified for the array in the
variable's declaration, the program should abort with an error message.
Errata/Clarifications
- 09/19/2007: Deleted reference to the initial value of boolean
array elements, since TL07 only has integer arrays.
- 08/28/2007: Corrected the semantics for operators to use the
correct Symbols. Tweaked the wording of the array index rule.