CpS 450 Language Translation Systems

MiniDream Semantics

Block Structure

The MiniDream language is a block-structured subset of the Dream language. Blocks are created by 1) defining a class and 2) defining a method.

Identifiers are visible from the point of declaration to the end of the block in which they are defined. There are basically three scope levels in MiniDream:

  • the global scope, containing predefined identifiers and names of user-defined classes

  • class scope, containing a class’s methods and attributes

  • local scope, containing local variables and method parameters

Predefined Identifiers

Identifiers must be declared before they are used, with the exception of these predefined identifiers:

  • in refers to an object of class Reader. The Reader class contains one method:

    readint(): int - reads a line from standard input, converts it to an integer, and returns it

  • out refers to an object of class Writer. The Writer class contains one method:

    writeint(num: int) - prints num to standard output, followed by a newline.

User Defined Types

MiniDream allows the user to define classes (indeed, this is the only way a program can be written). MiniDream does not use the inherits from clause or the string or array type. Your compiler should issue an “unsupported feature” message if these features are present in the user’s program.

MiniDream requires that the user define exactly one class in a file. Also, MiniDream does not allow variables of a class type to be defined (can’t define additional Reader/Writer variables).

Attributes

Class-level variables (“attributes”) must be defined with a type and no initializer expression. Display a “feature unsupported” message if the user attempts to use an initializer expression.

Methods

The only method MiniDream supports is the start method, defined like this:

start()
begin
  ~ ... code for main program
end

The MiniDream compiler should issue a “feature unsupported” error message if any other methods are defined in the user’s program, or if local variables are defined in the start( ) method. However, please note that the MiniDream compiler must perform complete semantic checks on programs containing multiple methods, with both class-level and local variables.

Expressions

MiniDream does not support the use of the following expressions:

  • variable initializer expressions

  • new id

  • me

  • null

  • array indexing

Your compiler should report “feature unsupported” messages when any of these appear in a user’s program, and may treat them as having a data type of “unknown” or “error”.

Note that since MiniDream does not support variable initializer expressions, the user is required to supply a data type in a variable definition (the data type is not optional in MiniDream).

Statements

Assignment Statement

LHS := RHS

At runtime, the assignment statement evaluates the expression on the RHS to compute its value. It stores the value in the variable on the LHS, after verifying that the type of the LHS is compatible with the type of the RHS expression.

Array indexing on the LHS is not permitted in MiniDream.

if and while Statement

The if and while statement have semantics identical to their Java / C++ counterparts.

Call Statement

The call statement can be used to invoke void or non-void methods. If a non-void method is invoked, the return value is ignored.