The Programming Language Oberon

Preparing link to download Please wait... Download


E-Book Content

1 The Programming Language Oberon (Revision 1. 10. 90) N.Wirth Make it as simple as possible, but not simpler. (A. Einstein) 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 to relate 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. 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 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. 1. Identifiers are sequences of letters and digits. The first character must be a letter. ident = letter {letter | digit}. Examples: x scan Oberon GetSymbol firstLetter 2. 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 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 this case it is of type LONGREAL. 2 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 12.3 4.567E8 0.57712566D-6 = 256 = 456700000 = 0.00000057712566 3. 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". 4. 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 9.1 and 8.2.4). str