Skip to content

Language Semantics

Michael Grossniklaus edited this page Dec 21, 2020 · 3 revisions

The following summarizes the language rules of Oberon that the LLVM frontend for Oberon is currently checking during semantic analysis.

Name Declaration

All names (identifiers) in the same scope must be unique, regardless of whether they refer to constants, types, variables, or procedures. Duplicate declarations must be reported.

Constants

The expression must evaluate to a constant.

Arrays

The expression must be constant and evaluate to a number larger than 0. The specified type must exist.

Records

A record defines a new scope. The names of the declared record fields must be unique in this scope. The specified types must exist.

Variables

The specified types must exist.

Procedures

A procedure defines a new scope. All names declared in the procedure must be unique in this scope. Formal parameters that have a structured type (ARRAY or RECORD) cannot be VAR-parameters. Values of structured types are always passed by reference.

Expressions

Expressions must by type-checked and use of invalid types must be reported. Constant expressions must be evaluated.

Arithmetic Operators

Both arguments must be INTEGER values, the result is of type INTEGER.

Comparison Operators

Both arguments must have the same type, the result is of type BOOLEAN.

Boolean Operators

Arguments must be BOOLEAN values, the result is of type BOOLEAN.

Name Use

Names must be declared before they can be used. Undeclared names must be reported. Oberon follows lexical scoping, i.e., if a name is not declared in the local scope, its enclosing scopes are checked.

Variables and Actual Parameters

If a selector is present, it must be checked that the name refers to either an ARRAY or RECORD, respectively. If a selector references a RECORD-field, existence of this field must be checked. If a selector indexes an ARRAY-field and the index is given as a constant or constant expression, array bounds must be checked.

Procedure Calls

The number and types of the actual parameters must match the number and types of the formal parameters. Constant values and expressions cannot be passed as VAR-parameters. As a default, parameters are passed by value.

Statements

Assignments

The name on the left-hand side of the assignment must refer to a variable. The type of expression that is assigned must be compatible with the type of the variable.

IF-Statements

The type of expression representing the condition must of type BOOLEAN.

WHILE-Statements

The type of expression representing the condition must of type BOOLEAN.