</tr>
<tr>
<td class="first">/</td>
- <td>#</td>
+ <td>!=</td>
<td>case</td>
<td>mod</td>
<td class="last">type</td>
<pre>Tree = POINTER TO Node
</pre>
- <pre>Node = RECORD key: INTEGER;
+ <pre>Node = RECORD key: Int;
left, right: Tree
END
</pre>
END
</pre>
- <pre>Function = PROCEDURE (x: INTEGER): INTEGER
+ <pre>Function = PROCEDURE (x: Int): Int
</pre>
<h3><a name="sec6.1">6.1. Basic types</a></h3>
<div class="dl">
<dl>
- <dt>BOOLEAN</dt>
- <dd>the truth values TRUE and FALSE</dd>
+ <dt>Bool</dt>
+ <dd>the truth values true and false</dd>
- <dt>CHAR</dt>
+ <dt>Char</dt>
<dd>the characters of a standard character set</dd>
- <dt>INTEGER</dt>
+ <dt>Int</dt>
<dd>the integers</dd>
- <dt>REAL</dt>
+ <dt>Real</dt>
<dd>real numbers</dd>
- <dt>BYTE</dt>
+ <dt>Byte</dt>
<dd>the integers between 0 and 255</dd>
-
- <dt>SET</dt>
- <dd>the sets of integers between 0 and an implementation-dependent limit</dd>
</dl>
</div>
- <p>The type BYTE is compatible with the type INTEGER, and vice-versa.</p>
+ <p>The type Byte is compatible with the type Int, and vice-versa.</p>
<h3><a name="sec6.2">6.2. Array types</a></h3>
<p>Examples of array types:</p>
- <pre>ARRAY N OF INTEGER
+ <pre>ARRAY N OF Int
</pre>
<pre>ARRAY 10, 20 OF REAL
<p>Examples of record types:</p>
- <pre>RECORD day, month, year: INTEGER
+ <pre>RECORD day, month, year: Int
END
</pre>
<pre>RECORD
name, firstname: ARRAY 32 OF CHAR;
- age: INTEGER;
+ age: Int;
salary: REAL
END
</pre>
<p>Variables whose identifiers appear in the same list are all of the same type. Examples of variable declarations (refer to examples in <a href="https://miasap.se/obnc/oberon-report.html#sec6">Ch. 6</a>):</p>
- <pre>i, j, k: INTEGER
+ <pre>i, j, k: Int
</pre>
<pre>x, y: REAL
<pre>w: ARRAY 16 OF
RECORD ch: CHAR;
- count: INTEGER
+ count: Int
END
</pre>
<p>With the exception of sets and literal constants, i.e. numbers and strings, operands are denoted by <dfn>designators</dfn>. A designator consists of an identifier referring to the constant, variable, or procedure to be designated. This identifier may possibly be qualified by module identifiers (see <a href="https://miasap.se/obnc/oberon-report.html#sec4">Ch. 4</a> and <a href="https://miasap.se/obnc/oberon-report.html#sec11">11</a>), and it may be followed by selectors, if the designated object is an element of a structure.</p>
- <p>If <var>A</var> designates an array, then <var>A</var>[<var>E</var>] denotes that element of <var>A</var> whose index is the current value of the expression <var>E</var>. The type of <var>E</var> must be of type INTEGER. A designator of the form <var>A</var>[<var>E1</var>, <var>E2</var>, ... , <var>En</var>] stands for <var>A</var>[<var>E1</var>][<var>E2</var>] ... [<var>En</var>]. If <var>p</var> designates a pointer variable, <var>p</var>^ denotes the variable which is referenced by <var>p</var>. If <var>r</var> designates a record, then <var>r</var>.<var>f</var> denotes the field <var>f</var> of <var>r</var>. If <var>p</var> designates a pointer, <var>p</var>.<var>f</var> denotes the field <var>f</var> of the record <var>p</var>^, i.e. the dot implies dereferencing and <var>p</var>.<var>f</var> stands for <var>p</var>^.<var>f</var>.</p>
+ <p>If <var>A</var> designates an array, then <var>A</var>[<var>E</var>] denotes that element of <var>A</var> whose index is the current value of the expression <var>E</var>. The type of <var>E</var> must be of type Int. A designator of the form <var>A</var>[<var>E1</var>, <var>E2</var>, ... , <var>En</var>] stands for <var>A</var>[<var>E1</var>][<var>E2</var>] ... [<var>En</var>]. If <var>p</var> designates a pointer variable, <var>p</var>^ denotes the variable which is referenced by <var>p</var>. If <var>r</var> designates a record, then <var>r</var>.<var>f</var> denotes the field <var>f</var> of <var>r</var>. If <var>p</var> designates a pointer, <var>p</var>.<var>f</var> denotes the field <var>f</var> of the record <var>p</var>^, i.e. the dot implies dereferencing and <var>p</var>.<var>f</var> stands for <var>p</var>^.<var>f</var>.</p>
<p>The <dfn>typeguard</dfn> <var>v</var>(<var>T0</var>) asserts that <var>v</var> is of type <var>T0</var> , i.e. it aborts program execution, if it is not of type <var>T0</var> . The guard is applicable, if</p>
<table>
<tbody><tr>
<td class="first">i</td>
- <td class="last">(INTEGER)</td>
+ <td class="last">(Int)</td>
</tr>
<tr>
<td class="first">a[i]</td>
</tr>
<tr>
<td class="first">t.key</td>
- <td class="last">(INTEGER)</td>
+ <td class="last">(Int)</td>
</tr>
<tr>
<td class="first">t.left.right</td>
<p>The syntax of expressions distinguishes between four classes of operators with different precedences (binding strengths). The operator ~ has the highest precedence, followed by multiplication operators, addition operators, and relations. Operators of the same precedence associate from left to right. For example, <var>x</var> − <var>y</var> − <var>z</var> stands for (<var>x</var> − <var>y</var>) − <var>z</var>.</p>
<pre>expression = SimpleExpression [relation SimpleExpression].
-relation = "=" | "#" | "<" | "<=" | ">" | ">=" | IN | IS.
+relation = "=" | "!=" | "<" | "<=" | ">" | ">=" | IS.
SimpleExpression = ["+"|"-"] term {AddOperator term}.
AddOperator = "+" | "-" | OR.
term = factor {MulOperator factor}.
MulOperator = "*" | "/" | DIV | MOD | "&" .
factor = number | string | NIL | TRUE | FALSE |
- set | designator [ActualParameters] | "(" expression ")" | "~" factor.
-set = "{" [element {"," element}] "}".
-element = expression [".." expression].
+ designator [ActualParameters] | "(" expression ")" | "~" factor.
ActualParameters = "(" [ExpList] ")" .
</pre>
- <p>The set {<var>m</var> .. <var>n</var>} denotes {<var>m</var>, <var>m</var>+1, … , <var>n</var>-1, <var>n</var>}, and if <var>m</var> > <var>n</var>, the empty set. The available operators are listed in the following tables. In some instances, several different operations are designated by the same operator symbol. In these cases, the actual operation is identified by the type of the operands.</p>
-
<h4><a name="sec8.2.1">8.2.1. Logical operators</a></h4>
<div class="table">
<pre><var>x</var> = <var>q</var>*<var>y</var> + <var>r</var> 0 <= <var>r</var> < <var>y</var>
</pre>
- <h4><a name="sec8.2.3">8.2.3. Set operators</a></h4>
-
- <div class="table">
- <table class="header">
- <tbody><tr>
- <th class="first">symbol</th>
- <th class="last">result</th>
- </tr>
- <tr class="second">
- <td class="first">+</td>
- <td class="last">union</td>
- </tr>
- <tr>
- <td class="first">−</td>
- <td class="last">difference</td>
- </tr>
- <tr>
- <td class="first">*</td>
- <td class="last">intersection</td>
- </tr>
- <tr>
- <td class="first">/</td>
- <td class="last"> symmetric set difference</td>
- </tr>
- </tbody></table>
- </div>
-
- <p>When used with a single operand of type SET, the minus sign denotes the set complement.</p>
-
<h4><a name="sec8.2.4">8.2.4. Relations</a></h4>
<div class="table">
<td class="last">equal</td>
</tr>
<tr>
- <td class="first">#</td>
+ <td class="first">!=</td>
<td class="last">unequal</td>
</tr>
<tr>
<td class="first">>=</td>
<td class="last">greater or equal</td>
</tr>
- <tr>
- <td class="first">IN</td>
- <td class="last">set membership</td>
- </tr>
<tr>
<td class="first">IS</td>
<td class="last">type test</td>
<p>Relations are Boolean. The ordering relations <, <=, >, >= apply to the numeric types, CHAR, and character arrays. The relations = and # also apply to the types BOOLEAN, SET, and to pointer and procedure types.</p>
- <p><var>x</var> IN <var>s</var> stands for “<var>x</var> is an element of <var>s</var>”. <var>x</var> must be of type INTEGER, and <var>s</var> of type SET.</p>
-
<p><var>v</var> IS <var>T</var> stands for “<var>v</var> is of type <var>T</var>” and is called a <dfn>type test</dfn>. It is applicable, if</p>
<ol>
<table>
<tbody><tr>
<td class="first">1987</td>
- <td class="last">(INTEGER)</td>
+ <td class="last">(Int)</td>
</tr>
<tr>
<td class="first">i DIV 3</td>
- <td class="last">(INTEGER)</td>
+ <td class="last">(Int)</td>
</tr>
<tr>
<td class="first">~p OR q</td>
</tr>
<tr>
<td class="first">(i+j) * (i-j)</td>
- <td class="last">(INTEGER)</td>
- </tr>
- <tr>
- <td class="first">s - {8, 9, 13}</td>
- <td class="last">(SET)</td>
+ <td class="last">(Int)</td>
</tr>
<tr>
<td class="first">a[i+j] * a[i-j]</td>
<td class="first">t.key = 0</td>
<td class="last">(BOOLEAN)</td>
</tr>
- <tr>
- <td class="first">k IN {i .. j-1}</td>
- <td class="last">(BOOLEAN)</td>
- </tr>
<tr>
<td class="first">t IS CenterNode</td>
<td class="last">(BOOLEAN)</td>
<td class="first">WriteInt(2*j + 1, 6)</td>
<td class="last"></td>
</tr>
- <tr>
- <td class="first">INC(w[k].count)</td>
- <td class="last"></td>
- </tr>
</tbody></table>
</div>
<h3><a name="sec9.5">9.5. Case statements</a></h3>
- <p>Case statements specify the selection and execution of a statement sequence according to the value of an expression. First the case expression is evaluated, then the statement sequence is executed whose case label list contains the obtained value. If the case expression is of type INTEGER or CHAR, all labels must be integers or single-character strings, respectively.</p>
+ <p>Case statements specify the selection and execution of a statement sequence according to the value of an expression. First the case expression is evaluated, then the statement sequence is executed whose case label list contains the obtained value. If the case expression is of type Int or CHAR, all labels must be integers or single-character strings, respectively.</p>
<pre>CaseStatement = CASE expression OF case {"|" case} END.
case = [CaseLabelList ":" StatementSequence].
<p>Example:</p>
- <pre>TYPE R = RECORD a: INTEGER END;
- R0 = RECORD (R) b: INTEGER END;
+ <pre>TYPE R = RECORD a: Int END;
+ R0 = RECORD (R) b: Int END;
R1 = RECORD (R) b: REAL END;
R2 = RECORD (R) b: SET END;
P = POINTER TO R;
WHILE v >= end DO S; v := v + inc END
</pre>
- <p>The types of <var>v</var>, <var>beg</var> and <var>end</var> must be INTEGER, and <var>inc</var> must be an integer (constant expression). If the step is not specified, it is assumed to be 1.</p>
+ <p>The types of <var>v</var>, <var>beg</var> and <var>end</var> must be Int, and <var>inc</var> must be an integer (constant expression). If the step is not specified, it is assumed to be 1.</p>
<h2><a name="sec10">10. Procedure declarations</a></h2>
<p>Examples of procedure declarations:</p>
- <pre>PROCEDURE ReadInt(VAR x: INTEGER);
- VAR i: INTEGER; ch: CHAR;
+ <pre>PROCEDURE ReadInt(VAR x: Int);
+ VAR i: Int; ch: CHAR;
BEGIN i := 0; Read(ch);
WHILE ("0" <= ch) & (ch <= "9") DO
i := 10*i + (ORD(ch) - ORD("0")); Read(ch)
END ReadInt
</pre>
- <pre>PROCEDURE WriteInt(x: INTEGER); (* 0 <= x < 10^5 *)
- VAR i: INTEGER;
- buf: ARRAY 5 OF INTEGER;
+ <pre>PROCEDURE WriteInt(x: Int); (* 0 <= x < 10^5 *)
+ VAR i: Int;
+ buf: ARRAY 5 OF Int;
BEGIN i := 0;
REPEAT buf[i] := x MOD 10; x := x DIV 10; INC(i) UNTIL x = 0;
REPEAT DEC(i); Write(CHR(buf[i] + ORD("0"))) UNTIL i = 0
END WriteInt
</pre>
- <pre>PROCEDURE log2(x: INTEGER): INTEGER;
- VAR y: INTEGER; (*assume x>0*)
+ <pre>PROCEDURE log2(x: Int): Int;
+ VAR y: Int; (*assume x>0*)
BEGIN y := 0;
WHILE x > 1 DO x := x DIV 2; INC(y) END;
RETURN y
<th class="last">Function</th>
</tr>
<tr class="second">
- <td class="first">ABS(x)</td>
+ <td class="first">Abs(x)</td>
<td>x: numeric type</td>
<td>type of x</td>
<td class="last">absolute value</td>
</tr>
<tr>
- <td class="first">ODD(x)</td>
- <td>x: INTEGER</td>
- <td>BOOLEAN</td>
- <td class="last">x MOD 2 = 1</td>
- </tr>
- <tr>
- <td class="first">LEN(v)</td>
+ <td class="first">Length(v)</td>
<td> v: array</td>
- <td>INTEGER</td>
+ <td>Int</td>
<td class="last">the length of v</td>
</tr>
- <tr>
- <td class="first">LSL(x, n)</td>
- <td>x, n: INTEGER</td>
- <td>INTEGER</td>
- <td class="last">logical shift left, x * 2<sup>n</sup></td>
- </tr>
- <tr>
- <td class="first">ASR(x, n)</td>
- <td>x, n: INTEGER</td>
- <td>INTEGER</td>
- <td class="last">signed shift right, x DIV 2<sup>n</sup></td>
- </tr>
- <tr>
- <td class="first">ROR(x, n)</td>
- <td>x, n: INTEGER</td>
- <td>INTEGER</td>
- <td class="last">x rotated right by n bits</td>
- </tr>
</tbody></table>
</div>
</tr>
<tr>
<td class="first">AsInt(x)</td>
- <td>Char, Bool, Set</td>
+ <td>Char, Bool</td>
<td>Int</td>
<td class="last">ordinal number of x</td>
</tr>
<td>Int</td>
<td class="last">v := v - n</td>
</tr>
- <tr class="group-first">
- <td class="first">Include(v, x)</td>
- <td>v: Set; x: Int</td>
- <td class="last">v := v + {x}</td>
- </tr>
- <tr>
- <td class="first">Exclude(v, x)</td>
- <td>v: Set; x: Int</td>
- <td class="last">v := v - {x}</td>
- </tr>
<tr class="group-first">
<td class="first">New(v)</td>
<td>pointer type</td>
BEGIN Texts.Write(W, ch)
END;
- PROCEDURE WriteInt*(x, n: INTEGER);
- VAR i: INTEGER; a: ARRAY 16 OF CHAR;
+ PROCEDURE WriteInt*(x, n: Int);
+ VAR i: Int; a: ARRAY 16 OF CHAR;
BEGIN i := 0;
IF x < 0 THEN Texts.Write(W, "-"); x := -x END ;
REPEAT a[i] := CHR(x MOD 10 + ORD("0")); x := x DIV 10; INC(i) UNTIL x = 0;
</pre>
<pre>expression = SimpleExpression [relation SimpleExpression].
-relation = "=" | "#" | "<" | "<=" | ">" | ">=" | IN | IS.
+relation = "=" | "!=" | "<" | "<=" | ">" | ">=" | IS.
SimpleExpression = ["+" | "-"] term {AddOperator term}.
AddOperator = "+" | "-" | OR.
term = factor {MulOperator factor}.
MulOperator = "*" | "/" | DIV | MOD | "&".
factor = number | string | NIL | TRUE | FALSE |
- set | designator [ActualParameters] | "(" expression ")" | "~" factor.
+ designator [ActualParameters] | "(" expression ")" | "~" factor.
designator = qualident {selector}.
selector = "." ident | "[" ExpList "]" | "^" | "(" qualident ")".
-set = "{" [element {"," element}] "}".
-element = expression [".." expression].
ExpList = expression {"," expression}.
ActualParameters = "(" [ExpList] ")" .
</pre>