Oberon Language Report

Author: N. Wirth. Link to original: http://www-old.oberon.ethz.ch/oreport.html (English).
Tags: Oberon, Programming, программирование Submitted by MixeratoR 28.01.2010. Public material.
Оригинальное (1990) изложение языка Oberon (потомок Pascal и Modula-2).

Translations of this material:

into Russian: Сообщение о языке Оберон. 13% translated in draft.
Submitted for translation by MixeratoR 28.01.2010

Text

Revised Edition 1. 10. 90, N. Wirth

Make it as simple as possible, but not simpler.

A. Einstein

--------------------------------------------------------------------------------

Introduction

Syntax

Vocabulary and representation

Declarations and scope rules

Constant declarations

Type declarations

Variable declarations

Expressions

Statements

Procedure declarations

Modules

The Module SYSTEM

--------------------------------------------------------------------------------

1. Introduction

Oberon is a general-purpose programming language that evolved from Modula-2. Its principal new feature is the concept of type extension. It permits the construction of new data types on the basis of existing ones and provides relations between them.

This report is not intended as a programmer's tutorial. It is intentionally kept concise. Its function is to serve as a reference for programmers, implementors, and manual writers. What remains unsaid is mostly left so intentionally, either because it is derivable from stated rules of the language or because it would require to commit the definition when a general commitment appears as unwise.

2. Syntax

A language is an infinite set of sentences, namely the sentences well formed according to its syntax. In Oberon, these sentences are called compilation units. Each unit is a finite sequence of symbols from a finite vocabulary. The vocabulary of Oberon consists of identifiers, numbers, strings, operators, delimiters, and comments. They are called lexical symbols and are composed of sequences of characters. (Note the distinction between symbols and characters.)

To describe the syntax, an extended Backus-Naur Formalism called EBNF is used. Brackets [ and ] denote optionality of the enclosed sentential form, and braces { and } denote its repetition (possibly 0 times). Syntactic entities (non-terminal symbols) are denoted by English words expressing their intuitive meaning. Symbols of the language vocabulary (terminal symbols) are denoted by strings enclosed in quote marks or words written in capital letters, so-called reserved words. Syntactic rules (productions) are marked by a $ sign at the left margin of the line.

3. Vocabulary and representation

The representation of symbols in terms of characters is defined using the ASCII set. Symbols are identifiers, numbers, strings, operators, delimiters, and comments. The following lexical rules must be observed. Blanks and line breaks must not occur within symbols (except in comments, and in the case of blanks in strings). They are ignored unless they are essential to separate two consecutive symbols. Capital and lower-case letters are considered as being distinct.

Identifiers are sequences of letters and digits. The first character must be a letter.

$ ident = letter {letter | digit}.

Examples:

x scan Oberon GetSymbol firstLetter

Numbers are (unsigned) integers or real numbers. Integers are sequences of digits and may be followed by a suffix letter. The type is the minimal type to which the number belongs (see Section 6.1.). If no suffix is specified, the representation is decimal. The suffix H indicates hexadecimal representation.

A real number always contains a decimal point. Optionally, it may also contain a decimal scale factor. The letter E (or D) is pronounced as 'times ten to the power of'. A real number is of type REAL, unless it has a scale factor containing the letter D, in which case it is of type LONGREAL.

$ number = integer | real.

$ integer = digit {digit} | digit {hexDigit} "H" .

$ real = digit {digit} "." {digit} [ScaleFactor].

$ ScaleFactor = ("E" | "D") ["+" | "-"] digit {digit}.

$ hexDigit = digit | "A" | "B" | "C" | "D" | "E" | "F".

$ digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9".

Examples:

1987

100H = 256

12.3

4.567E8 = 456700000

0.57712566D-6 = 0.00000057712566

Character constants are either denoted by a single character enclosed in quote marks or by the ordinal number of the character in hexadecimal notation followed by the letter X.

$ CharConstant = """ character """ | digit {hexDigit} "X".

Strings are sequences of characters enclosed in quote marks ("). A string cannot contain a quote mark. The number of characters in a string is called the length of the string. Strings can be assigned to and compared with arrays of characters (see Sections 9.1 and 8.2.4).

$ string = """ {character} """ .

Examples:

"OBERON" "Don't worry!"

Operators and delimiters are the special characters, character pairs, or reserved words listed below. These reserved words consist exclusively of capital letters and cannot be used in the role of identifiers.

+ := ARRAY IS TO

- ^ BEGIN LOOP TYPE

* = CASE MOD UNTIL

/ # CONST MODULE VAR

~ < DIV NIL WHILE

& > DO OF WITH

. <= ELSE OR

, >= ELSIF POINTER

; .. END PROCEDURE

| : EXIT RECORD

( ) IF REPEAT

[ ] IMPORT RETURN

{ } IN THEN

Comments may be inserted between any two symbols in a program. They are arbitrary character sequences opened by the bracket (* and closed by *). Comments do not affect the meaning of a program.

4. Declarations and scope rules

Every identifier occurring in a program must be introduced by a declaration, unless it is a predefined identifier. Declarations also serve to specify certain permanent properties of an object, such as whether it is a constant, a type, a variable or a procedure.

The identifier is then used to refer to the associated object. This is possible in those parts of a program only which are within the scope of the declaration. No identifier may denote more than one object within a given scope. The scope extends textually from the point of the declaration to the end of the block (procedure or module) to which the declaration belongs and hence to which the object is local. The scope rule has the following amendments:

If a type T is defined as POINTER TO T1 (see Section 6.4), the identifier T1 can be declared textually following the declaration of T, but it must lie within the same scope.

Field identifiers of a record declaration (see Section 6.3) are valid in field designators only.

In its declaration, an identifier in the global scope may be followed by an export mark (*) to indicate that it be exported from its declaring module. In this case, the identifier may be used in other modules, if they import the declaring module. The identifier is then prefixed by the identifier designating its module (see Section 11). The prefix and the identifier are separated by a period and together are called a qualified identifier.

$ qualident = [ident "."] ident.

$ identdef = ident ["*"].

The following identifiers are predefined; their meaning is defined in the indicated sections:

ABS (10.2) LEN (10.2)

ASH (10.2) LONG (10.2)

BOOLEAN (6.1) LONGINT (6.1)

CAP (10.2) LONGREAL (6.1)

CHAR (6.1) MAX (10.2)

CHR (10.2) MIN (10.2)

COPY (10.2) NEW (6.4)

DEC (10.2) ODD (10.2)

ENTIER (10.2) ORD (10.2)

EXCL (10.2) REAL (6.1)

FALSE (6.1) SET (6.1)

HALT (10.2) SHORT (10.2)

INC (10.2) SHORTINT (6.1)

INCL (10.2) SIZE (10.2)

INTEGER (6.1) TRUE (6.1)

5. Constant declarations

A constant declaration associates an identifier with a constant value.

$ ConstantDeclaration = identdef "=" ConstExpression.

$ ConstExpression = expression.

A constant expression can be evaluated by a mere textual scan without actually executing the program. Its operands are constants (see Section 8).

Examples:

N = 100

limit = 2*N -1

all = {0 .. WordSize-1}

6. Type declarations

A data type determines the set of values that variables of that type may assume, and the operators that are applicable. A type declaration is used to associate an identifier with the type. Such association may be with unstructured (basic) types, or it may be with structured types, in which case it defines the structure of variables of this type and, by implication, the operators that are applicable to the components. There are two different structures, namely arrays and records, with different component selectors.

$ TypeDeclaration = identdef "=" type.

Pages: ← previous Ctrl next
1 2 3 4 5 6

© 2002 ETH Zürich.