The TL07 Language Introduction

The TL07 programming language, is based on the P2K language used by Michael Franz in his Advanced Compiler Construction class at the University of California, Irvine. The P2K language was a simplified subset of Pascal, and TL07 has been simplified even further, so that you can experience writing an optimizing compiler without getting burdened by all of the complexities and details of a complete, standard programming language.

Lexical Features

The TL07 language, is lexically simple. All lexical items are to be separated by one or more whitespace characters (i.e., spaces, tabs, and returns). All identifiers start with a lower case letter, and may contain only numbers and lower case letters. All key words are made of a capital letters. In addition the symbols "[", "]", "(", ")", ":=", ";", "*", "/", "%", "+", "-", "==", "!=", "<", "<=", ">", ">=" are used.

Data Types

TL07 supports 32-bit integers ("INT"), booleans ("BOOL"), arrays of INT. The syntax for an array type is "ARRAY posnum OF INT", where posnum is the size of the array. Variables are always declared to be of a particular type.

Operators

TL07 has several infix binary operators that work on either integer operands. The multiplication "*", division "/", modulus "%", addition "+", and subtraction "-" produce integer results. The comparison operators (i.e., equals "==", not equal "!=", less than "<", less-than or equal-to "<=", greater than ">", and greater-than or equal-to ">=") all produce boolean results.

Control Structures

TL07 is a structured programming language. The only control structures supported are IF and WHILE statements. Both take a boolean expression that guards the body of the control structure. In the case of an IF statement, the statements after the THEN are executed if the expression is true, and the statements after the ELSE (if there is one) are executed if the expression is false. In the case of the WHILE statement, the loop is exited if the expression false; otherwise if the expression is true, the body will be executed, and then the expression will be re-evaluated.

Assignment

Assignments are a kind of statement rather than a kind of operator. The ":=" keyword is used to separate the left hand side (which is the variable or array element being assigned to) from the right hand side, which is an expression that must be of the same type as the left hand side.

Built-in Procedures

TL07 does not support user-defined functions or procedures, but it does support one built-in procedures WRITEINT that outputs an integer and a new-line to the console (respectively), and one user-defined function, READINT that reads an integer from the console. The syntax for these is hard-coded into TL07's BNF grammar.

Example TL07 Programs

Errata/Clarifications