SIMPL Compiler Project

SIMPL (Small Imperative Programming Language) is a small language suitable for a project in a compiler design class. A brief description of the language follows.  For information on the compiler implementation see documents on:

Lexical Analysis
Syntactic Analysis
Semantic Analysis
Runtime Support
Code Generation

Description

SIMPL is a language that manipulates integers and boolean values. A SIMPL program has the form:

progName(inputVariables) |localVariables| body !

Both the input variable list and the local variable list are lists of variable names, separated by spaces. A variable declaration with no additional qualifier is assumed to be of type integer.  A variable may be declared as type boolean by using the boolean qualifier as follows:

            glob’bool (x y ‘bool) |z’bool w|

In this example, the out variable glob, the in variable y and the local variable z, all have been declared as boolean.  The remaining variables, x and w are integer.  The form of the boolean qualifier is a single quote separator followed by the keyword bool.

 

The body of the program is a list of statements. There are three statement types: assignment, conditional, and iterative.

The assignment statement has the form:             

variableName <- expression !

The conditional has the form

if expression ? thenStatements : elseStatements !

The iterative statement has the form:

while expression ? loopStatements !

Expressions are composed of the relational operators > and =, the arithmetic operators +, -, *, and /, with the usual meanings and order of evaluation, variable names, and integer constants.

A SIMPL program is executed by reading in values for the input variables, executing the body of the program, and outputting the return value. The return value of the program is the last value assigned to the program name.