<?xml version="1.0" encoding='utf-8'?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<card id="card1" title="Oberon-2 - Page 9 - Wikipedia">
<p>
<a accesskey="1" href="page.php?w=Oberon-2&amp;p=8">1.Previous</a><br />
<a accesskey="3" href="page.php?w=Oberon-2&amp;p=10">3.Next</a>
</p>
<p>       IF name = p.name^ THEN RETURN END;        IF name < p.name^ THEN p := p.left ELSE p := p.right END    UNTIL p = NIL;    NEW(p); p.left := NIL; p.right := NIL; NEW(p.name, LEN(name)+1); COPY(name, p.name^);    IF name < father.name^ THEN father.left := p ELSE father.right := p ENDEND Insert;</p>

<p>PROCEDURE (t: Tree) Search* (name: ARRAY OF CHAR): Tree;    VAR p: Tree;BEGIN p := t;    WHILE (p # NIL) & (name # p.name^) DO        IF name < p.name^ THEN p := p.left ELSE p := p.right END    END;    RETURN pEND Search;</p>

<p>PROCEDURE NewTree* (): Tree;    VAR t: Tree;BEGIN NEW(t); NEW(t.name, 1); t.name[0] := 0X; t.left := NIL; t.right := NIL; RETURN tEND NewTree;</p>

<p>END Trees.</p>

<p><big> Oberon-2 extensions to Oberon </big></p>
<p>Source:</p>

<p><big> Type-bound procedures </big></p>
<p>Procedures can be bound to a record (or pointer) type. They are equivalent to instance methods in object-oriented terminology.</p>

<p><big> Read-only export </big></p>
<p>The use of exported variables and record fields can be restricted to read-only access. This is shown with a "-" visibility flag.</p>

<p><big> Open arrays </big></p>
<p>Open arrays which formerly could only be declared as formal parameter types may now be declared as pointer base types.</p>

<p><big> FOR statement </big></p>
<p>The <code>FOR</code> statement of Pascal and Modula-2 was not implemented in Oberon. It is reintroduced in Oberon-2.</p>

<p><big> Runtime type checking </big></p>
<p>Oberon-2 provides several mechanisms for checking the dynamic type of an object. For example, where a Bird object might be instantiated to either a Duck or a Cuckoo, Oberon-2 allows the programmer to respond to the actual type of the object at runtime.</p>

<p>The first, most conventional, approach is to rely on the type binding system. The second approach is to use the <code>WITH</code> statement, which allows the dynamic <a href="page.php?w=Subtyping">subtype</a> of a variable to be checked directly. In both cases, once the subtype has been identified, the programmer can make use of any type-bound procedures or variables that are appropriate to the subtype. Examples of these approaches are shown below.</p>

<p>Note that the form of <code>WITH</code> statement used in Oberon-2 is unrelated to the Pascal and Modula-2 WITH statement. This method of abbreviating access to record fields is not implemented in Oberon or Oberon-2.</p>

<p><big> Type binding </big></p>
<p><syntaxhighlight lang="componentpascal"> MODULE Birds;     TYPE         Bird* = RECORD             sound* : ARRAY 10 OF CHAR;         END; END Birds.  MODULE Ducks;     IMPORT Birds;      TYPE         Duck* = RECORD (Birds.Bird) END;      PROCEDURE SetSound* (VAR bird : Duck);     BEGIN         bird.sound := "Quack!"      END SetSound; END Ducks.  MODULE Cuckoos;     IMPORT Birds;      TYPE         Cuckoo* = RECORD (Birds.Bird) END;      PROCEDURE SetSound* (VAR bird : Cuckoo);     BEGIN         bird.sound := "Cuckoo!"     END SetSound; END Cuckoos.</syntaxhighlight></p>

<p><big> <code>WITH</code> statement </big></p>
<p><syntaxhighlight lang="componentpascal"> MODULE Test;     IMPORT Out, Birds, Cuckoos, Ducks;      TYPE         SomeBird* = RECORD (Birds.Bird) END;      VAR         sb : SomeBird;         c  : Cuckoos.Cuckoo;         d  : Ducks.Duck;      PROCEDURE SetSound* (VAR bird : Birds.Bird);     BEGIN         WITH bird : Cuckoos.Cuckoo DO              bird.sound := "Cuckoo!"            | bird : Ducks.Duck DO              bird.sound := "Quack!"         ELSE              bird.sound := "Tweet!"         END     END SetSound;      PROCEDURE MakeSound* (VAR b : Birds.Bird);     BEGIN         Out.Ln;         Out.String(b.sound);         Out.Ln     END MakeSound;  BEGIN     SetSound(c);     SetSound(d);     SetSound(sb);      MakeSound(c);     MakeSound(d);     MakeSound(sb) END Test.</syntaxhighlight></p>

<p><big> <code>POINTER</code> </big></p>
<p><syntaxhighlight lang="componentpascal"> MODULE PointerBirds;     IMPORT Out;      TYPE         BirdRec*   = RECORD             sound* : ARRAY 10 OF CHAR;         END;         DuckRec*   = RECORD (BirdRec) END;         CuckooRec* = RECORD (BirdRec) END;          Bird   = POINTER TO BirdRec;         Cuckoo = POINTER TO CuckooRec;         Duck   = POINTER TO DuckRec;     VAR        pb : Bird;        pc : Cuckoo;        pd : Duck;      PROCEDURE SetDuckSound* (bird : Duck);     BEGIN         bird.sound := "Quack!"     END SetDuckSound;      PROCEDURE SetCuckooSound* (bird : Cuckoo);     BEGIN         bird.sound := "Cuckoo!"     END SetCuckooSound;      PROCEDURE SetSound* (bird : Bird);     BEGIN         WITH bird : Cuckoo DO              SetCuckooSound(bird)            | bird : Duck DO              SetDuckSound(bird)         ELSE              bird.sound := "Tweet!"         END     END SetSound;  BEGIN     NEW(pc);     NEW(pd);      SetCuckooSound(pc);     SetDuckSound(pd);      Out.Ln; Out.String(pc^.sound); Out.Ln;     Out.Ln; Out.String(pd^.sound); Out.Ln;      SetSound(pc);     SetSound(pd);      Out.Ln; Out.String(pc^.sound); Out.Ln;     Out.Ln; Out.String(pd^.sound); Out.Ln;  (* -------------------------------------- *) (* Pass dynamic type to procedure         *)      pb := pd;      SetDuckSound(pb(Duck));     Out.Ln; Out.String(pb^.sound); Out.Ln;      pb := pc;      SetCuckooSound(pb(Cuckoo));     Out.Ln; Out.String(pb^.sound); Out.Ln;  (* -------------------------------------- *)      SetSound(pb);     Out.Ln; Out.String(pb^.sound); Out.Ln;      pb := pd;      SetSound(pb);     Out.Ln; Out.String(pb^.sound); Out.Ln;  (* -------------------------------------- *)      NEW(pb);      SetSound(pb);     Out.Ln; Out.String(pb^.sound); Out.Ln END PointerBirds.</syntaxhighlight></p>

<p><big> <code>IS</code> operator </big></p>
<p>A third approach is possible using the <b><code>IS</code> operator</b>. This is a relation operator with the same precedence as equals (<code>=</code>), greater (<code>></code>), etc. but which tests dynamic type. Unlike the two other approaches, however, it does not allow the programmer access to the subtype that has been detected.</p>

<p><big> Syntax </big></p>
<p>The development of the <a href="page.php?w=ALGOL">ALGOL</a> -> <a href="page.php?w=Pascal_%28programming_language%29">Pascal</a> -> <a href="page.php?w=Modula-2">Modula-2</a> -> Oberon -> <a href="page.php?w=Component_Pascal">Component Pascal</a> language family is marked by a reduction in the complexity of the <a href="page.php?w=Syntax_%28programming_languages%29">language syntax</a>. The entire Oberon-2 language is described (Mössenböck & Wirth, March 1995) using only 33 grammatical productions in the <a href="page.php?w=extended_Backus-Naur_form">extended Backus-Naur form</a>, as shown below.</p>

<p><syntaxhighlight lang="ebnf">Module        = MODULE ident ";" [ImportList] DeclSeq [BEGIN StatementSeq] END ident ".".ImportList    = IMPORT [ident ":="] ident {"," [ident ":="] ident} ";".DeclSeq       = { CONST {ConstDecl ";" } | TYPE {TypeDecl ";"} | VAR {VarDecl ";"}} {ProcDecl ";" | ForwardDecl ";"}.ConstDecl     = IdentDef "=" ConstExpr.TypeDecl      = IdentDef "=" Type.VarDecl       = IdentList ":" Type.ProcDecl      = PROCEDURE [Receiver] IdentDef [FormalPars] ";" DeclSeq [BEGIN StatementSeq] END ident.ForwardDecl   = PROCEDURE "^" [Receiver] IdentDef [FormalPars].FormalPars    = "(" [FPSection {";" FPSection}] ")" [":" Qualident].FPSection     = [VAR] ident {"," ident} ":" Type.Receiver      = "(" [VAR] ident ":" ident ")".Type          = Qualident              | ARRAY [ConstExpr {"," ConstExpr}] OF Type              | RECORD ["("Qualident")"] FieldList {";" FieldList} END              | POINTER TO Type              | PROCEDURE [FormalPars].FieldList     = [IdentList ":" Type].StatementSeq  = Statement {";" Statement}.Statement     = [ Designator ":=" Expr              | Designator ["(" [ExprList] ")"]              | IF Expr THEN StatementSeq {ELSIF Expr THEN StatementSeq} [ELSE StatementSeq] END              | CASE Expr OF Case {"|" Case} [ELSE StatementSeq] END              | WHILE Expr DO StatementSeq END              | REPEAT StatementSeq UNTIL Expr              | FOR ident ":=" Expr TO Expr [BY ConstExpr] DO StatementSeq END              | LOOP StatementSeq END              | WITH Guard DO StatementSeq {"|" Guard DO StatementSeq} [ELSE StatementSeq] END              | EXIT              | RETURN [Expr]      ].	Case          = [CaseLabels {"," CaseLabels} ":" StatementSeq].CaseLabels    = ConstExpr [".." ConstExpr].Guard         = Qualident ":" Qualident.ConstExpr     = Expr.Expr          = SimpleExpr [Relation SimpleExpr].SimpleExpr    = ["+" | "-"] Term {AddOp Term}.Term          = Factor {MulOp Factor}.Factor        = Designator ["(" [ExprList] ")"] | number | character | string | NIL | Set | "(" Expr ")" | "~" Factor.Set           = "{" [Element {"," Element}] "}".Element       = Expr [".." Expr].Relation      = "=" | "#" | "<" | "<=" | ">" | ">=" | IN | IS.AddOp         = "+" | "-" | OR.MulOp         = "*" | "/" | DIV | MOD | "&".Designator    = Qualident {"." ident | "[" ExprList "]" | "^" | "(" Qualident ")"}.ExprList      = Expr {"," Expr}.IdentList     = IdentDef {"," IdentDef}.Qualident     = [ident "."] ident.IdentDef      = ident ["*" | "-"].</"></syntaxhighlight></p>

<p><big> Implementations </big></p>
<p>Oberon-2 compilers maintained by <a href="page.php?w=ETH">ETH</a> include versions for <a href="page.php?w=Windows">Windows</a>, <a href="page.php?w=Linux">Linux</a>, <a href="page.php?w=Oracle_Solaris">Solaris</a>, <a href="page.php?w=macOS">macOS</a>.</p>

<p>The  compiles to native machine code and can use a JIT on Windows, Linux, and macOS. It is created and maintained by <a href="page.php?w=Michael_Spivey">Mike Spivey</a> and uses the Keiko Virtual Machine.</p>

<p>There is an Oberon-2 <a href="page.php?w=Lex_%28software%29">Lex</a> scanner and <a href="page.php?w=Yacc">Yacc</a> <a href="page.php?w=parser">parser</a> by Stephen J. Bevan of Manchester University, UK, based on the one in the Mössenböck and Wirth reference. It is at version 1.4.</p>

<p>There is a release named <a href="page.php?w=Native_Oberon">Native Oberon</a> which includes an operating system, and can directly boot on PC class hardware.</p>

<p>A <a href="page.php?w=.NET">.NET</a> implementation of Oberon with the addition of some minor .NET-related extensions has been developed at ETHZ.</p>

<p> (POW!) is a very simple <a href="page.php?w=integrated_development_environment">integrated development environment</a>, which is provided with editor, linker, and Oberon-2 compiler. This compiles to <a href="page.php?w=Microsoft_Windows">Windows</a> executables. Full <a href="page.php?w=source_code">source code</a> is provided; the compiler is written in Oberon-2.</p>

<p>The  (JOB) was written at the University of Vologda in Russia. It produces object code in the form of Java class files (<a href="page.php?w=bytecode">bytecode</a>). Some JOB-specific classes are provided which are Java compatible, but which use a more Oberon-like component hierarchy.</p>

<p>The  compiles to C, using the <a href="page.php?w=GNU_Compiler_Collection">GNU Compiler Collection</a> (GCC) toolchain for program generation.</p>

<p> is a compiler that translates the full Oberon language into <a href="page.php?w=JavaScript">JavaScript</a>. The compiler is written in JavaScript and can thus be called from Web pages to process scripts written in Oberon.</p>

<p> is a development system by Excelsior LLC, Novosibirsk, Russia. It contains an optimizing compiler for Intel <a href="page.php?w=Pentium">Pentium</a>, or "via-C" translator for <a href="page.php?w=cross-platform_software">cross-platform software</a> development. Available for Windows and Linux. The compiler is written in Oberon-2 and compiles itself.</p>

<p> is a project to bring Oberon 2 and <a href="page.php?w=Component_Pascal">Component Pascal</a> (<a href="page.php?w=BlackBox_Component_Builder">BlackBox Component Builder</a>) to Linux and Win32. The Linux port of BlackBox was unavailable before and it originally ran on only Microsoft Windows.</p>

<p>XOberon is a <a href="page.php?w=real-time_operating_system">real-time operating system</a> for <a href="page.php?w=PowerPC">PowerPC</a>, written in Oberon-2.</p>

<p>The Portable Oberon-2 Compiler (OP2) was developed to port the <a href="page.php?w=Oberon_System">Oberon System</a> onto commercially available platforms.</p>

<p><big> Keiko bytecode </big></p>
<p>Oberon-2 can target the Keiko Virtual machine.For example, like some other language compilers (see <a href="page.php?w=O-code">O-code</a>, <a href="page.php?w=p-code">p-code</a>, etc.),the  first compiles to an intermediate bytecode (Keiko bytecode) which can be interpreted with a byte-code interpreter or use <a href="page.php?w=just-in-time_compilation">just-in-time compilation</a>.</p>

<p><big>See also</big></p>
<p>
* <a href="page.php?w=A2_%28operating_system%29">A2 (operating system)</a></p>

<p><big> References </big></p>
<p><big> Further reading </big></p>
<p>
* "" maintained at <a href="page.php?w=ETHZ">ETHZ</a><br/>
* "Second International Modula-2 Conference", September 1991.<br/>
*   Wirth (1990)<br/>
*  Wirth (1982)<br/>
*  Wirth (1990)<br/>
*  H. Mössenböck, N. Wirth, Institut für Computersysteme, <a href="page.php?w=ETH_Zurich">ETH Zurich</a>, January 1992 and  (1991) 12(4): 179-195.<br/>
* <br/>
*  Hanspeter Mössenböck (1994). (Available from  as PDF with the friendly permission of Springer-Verlag)<br/>
* <br/>
*  Niklaus Wirth & Jürg Gutknecht (2005)<br/>
*  Niklaus Wirth & Jürg Gutknecht (2013)</p>

<p><big> External links </big></p>
<p>
* , ETH Zürich<br/>
* <br/>
* <br/>
* <br/>
* </p>

<p></p>
<p>
<a accesskey="1" href="page.php?w=Oberon-2&amp;p=8">1.Previous</a><br />
<a accesskey="3" href="page.php?w=Oberon-2&amp;p=10">3.Next</a>
</p>

<do type="prev" label="Search">
        <go href="search.wml"/>
</do>

</card>
</wml>
