Oberon-2
   HOME

TheInfoList



OR:

Oberon-2 is an extension of the original
Oberon Oberon () is a king of the fairies in medieval and Renaissance literature. He is best known as a character in William Shakespeare's play ''A Midsummer Night's Dream'', in which he is King of the Fairies and spouse of Titania, Queen of the Fairi ...
programming language A programming language is a system of notation for writing computer programs. Most programming languages are text-based formal languages, but they may also be graphical. They are a kind of computer language. The description of a programming ...
that adds limited
reflection Reflection or reflexion may refer to: Science and technology * Reflection (physics), a common wave phenomenon ** Specular reflection, reflection from a smooth surface *** Mirror image, a reflection in a mirror or in water ** Signal reflection, in ...
and
object-oriented programming Object-oriented programming (OOP) is a programming paradigm based on the concept of "objects", which can contain data and code. The data is in the form of fields (often known as attributes or ''properties''), and the code is in the form of ...
facilities, open
arrays An array is a systematic arrangement of similar objects, usually in rows and columns. Things called an array include: {{TOC right Music * In twelve-tone and serial composition, the presentation of simultaneous twelve-tone sets such that the ...
as pointer base types, read-only field export, and reintroduces the FOR loop from Modula-2. It was developed in 1991 at ETH Zurich by
Niklaus Wirth Niklaus Emil Wirth (born 15 February 1934) is a Swiss computer scientist. He has designed several programming languages, including Pascal, and pioneered several classic topics in software engineering. In 1984, he won the Turing Award, generally ...
and Hanspeter Mössenböck, who is now at Institut für Systemsoftware (SSW) of the University of Linz, Austria. Oberon-2 is a superset of Oberon, is fully compatible with it, and was a redesign of
Object Oberon Object Oberon is a programming language which is based on the language Oberon with features for object-oriented programming Object-oriented programming (OOP) is a programming paradigm based on the concept of "objects", which can contain dat ...
. Oberon-2 inherited limited reflection and single
inheritance Inheritance is the practice of receiving private property, titles, debts, entitlements, privileges, rights, and obligations upon the death of an individual. The rules of inheritance differ among societies and have changed over time. Officia ...
("type extension") without the interfaces or
mixin In object-oriented programming languages, a mixin (or mix-in) is a class that contains methods for use by other classes without having to be the parent class of those other classes. How those other classes gain access to the mixin's methods depen ...
s from Oberon, but added efficient virtual methods ("type bound procedures"). Method calls were resolved at runtime using
C++ C++ (pronounced "C plus plus") is a high-level general-purpose programming language created by Danish computer scientist Bjarne Stroustrup as an extension of the C programming language, or "C with Classes". The language has expanded significan ...
-style virtual method tables. Compared to fully object-oriented languages like Smalltalk, in Oberon-2, basic data types and classes are not objects, many operations are not methods, there is no
message passing In computer science, message passing is a technique for invoking behavior (i.e., running a program) on a computer. The invoking program sends a message to a process (which may be an actor or object) and relies on that process and its support ...
(it can be emulated somewhat by reflection and through message extension, as demonstrated in ETH Oberon), and polymorphism is limited to subclasses of a common class (no
duck typing Duck typing in computer programming is an application of the duck test—"If it walks like a duck and it quacks like a duck, then it must be a duck"—to determine whether an object can be used for a particular purpose. With nominative ty ...
as in
Python Python may refer to: Snakes * Pythonidae, a family of nonvenomous snakes found in Africa, Asia, and Australia ** ''Python'' (genus), a genus of Pythonidae found in Africa and Asia * Python (mythology), a mythical serpent Computing * Python (pro ...
, and it's not possible to define interfaces as in
Java Java (; id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 151.6 million people, Java is the world's mos ...
). Oberon-2 does not support encapsulation at object or class level, but modules can be used for this purpose. Reflection in Oberon-2 does not use
metaobject In computer science, a metaobject is an object that manipulates, creates, describes, or implements objects (including itself). The object that the metaobject pertains to is called the base object. Some information that a metaobject might define incl ...
s, but simply reads from type descriptors
compiled In computing, a compiler is a computer program that translates computer code written in one programming language (the ''source'' language) into another language (the ''target'' language). The name "compiler" is primarily used for programs that ...
into the executable binaries, and exposed in the modules that define the types and/or procedures. If the format of these structures are exposed at the language level (as is the case for ETH Oberon, for example), reflection could be implemented at the
library A library is a collection of materials, books or media that are accessible for use and not just for display purposes. A library provides physical (hard copies) or digital access (soft copies) materials, and may be a physical location or a vir ...
level. It could thus be implemented almost entirely at library level, without changing the language code. Indeed, ETH Oberon makes use of language-level and library-level reflection abilities extensively. Oberon-2 provides built-in runtime support for
garbage collection Waste collection is a part of the process of waste management. It is the transfer of solid waste from the point of use and disposal to the point of treatment or landfill. Waste collection also includes the curbside collection of recyclabl ...
similar to Java and performs bounds and array index checks, etc., that eliminate the potential stack and array bounds overwriting problems and manual memory management issues inherent in C and C++. Separate compiling using symbol files and
namespace In computing, a namespace is a set of signs (''names'') that are used to identify and refer to objects of various kinds. A namespace ensures that all of a given set of objects have unique names so that they can be easily identified. Namespaces ...
s via the module architecture ensure fast rebuilds since only modules with changed interfaces need to be recompiled. The language Component Pascal is a refinement (a superset) of Oberon-2.


Example code

The following Oberon-2 code implements a simple binary tree: MODULE Trees; TYPE Tree* = POINTER TO Node; Node* = RECORD name-: POINTER TO ARRAY OF CHAR; left, right: Tree END; PROCEDURE (t: Tree) Insert* (name: ARRAY OF CHAR); VAR p, father: Tree; BEGIN p := t; REPEAT father := 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 END END Insert; 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 p END Search; PROCEDURE NewTree* (): Tree; VAR t: Tree; BEGIN NEW(t); NEW(t.name, 1); t.name := 0X; t.left := NIL; t.right := NIL; RETURN t END NewTree; END Trees.


Oberon-2 extensions to Oberon


Type-bound procedures

Procedures can be bound to a record (or pointer) type. They are equivalent to instance methods in object-oriented terminology.


Read-only export

The use of exported variables and record fields can be restricted to read-only access. This is shown with a "-" visibility flag.


Open arrays

Open arrays which formerly could only be declared as formal parameter types may now be declared as pointer base types.


FOR statement

The FOR statement of Pascal and Modula-2 was not implemented in Oberon. It is reintroduced in Oberon-2.


Runtime type checking

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. The first, most conventional, approach is to rely on the ''type binding system''. The second approach is to use the ''WITH statement'', which allows the dynamic
subtype Subtype may refer to: * Viral subtypes, such as Subtypes of HIV * Subtyping In programming language theory, subtyping (also subtype polymorphism or inclusion polymorphism) is a form of type polymorphism in which a subtype is a datatype that is ...
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. Note that the form of WITH 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.


Type binding

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.


WITH statement

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.


POINTER

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.


IS operator

A third approach is possible using the IS operator. This is a relation operator with the same precedence as equals (=), greater (>), 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.


Syntax

The development of the
ALGOL ALGOL (; short for "Algorithmic Language") is a family of imperative computer programming languages originally developed in 1958. ALGOL heavily influenced many other languages and was the standard method for algorithm description used by the ...
PascalModula-2 → Oberon → Component Pascal language family is marked by a ''reduction'' in the complexity of the language syntax. The entire Oberon-2 language is described (''Mössenböck & Wirth, March 1995'') using only 33 grammatical productions in the
extended Backus–Naur form In computer science, extended Backus–Naur form (EBNF) is a family of metasyntax notations, any of which can be used to express a context-free grammar. EBNF is used to make a formal description of a formal language such as a computer programm ...
, as shown below. Module = MODULE ident ";" mportListDeclSeq EGIN StatementSeqEND ident ".". ImportList = IMPORT dent ":="ident ";". DeclSeq = . ConstDecl = IdentDef "=" ConstExpr. TypeDecl = IdentDef "=" Type. VarDecl = IdentList ":" Type. ProcDecl = PROCEDURE eceiverIdentDef ormalPars";" DeclSeq EGIN StatementSeqEND ident. ForwardDecl = PROCEDURE "^" eceiverIdentDef ormalPars FormalPars = "(" PSection ")" :" Qualident FPSection = ARident ":" Type. Receiver = "(" ARident ":" ident ")". Type = Qualident , ARRAY onstExpr OF Type , RECORD ("Qualident")"FieldList END , POINTER TO Type , PROCEDURE ormalPars FieldList = dentList ":" Type StatementSeq = Statement . Statement = Designator ")"">("_[ExprList")"______________.html" ;"title="xprList")".html" ;"title="(" ("_[ExprList")"______________">_IF_Expr_THEN_StatementSeq__[ELSE_StatementSeqEND ______________.html" ;"title="xprList")"">(" ______________">_IF_Expr_THEN_StatementSeq__[ELSE_StatementSeqEND ______________">_CASE_Expr_OF_Case__[ELSE_StatementSeqEND ______________.html" ;"title="xprList")" "> IF Expr THEN StatementSeq [ELSE StatementSeqEND "> CASE Expr OF Case [ELSE StatementSeqEND "> WHILE Expr DO StatementSeq END , REPEAT StatementSeq UNTIL Expr , FOR ident ":=" Expr TO Expr [BY ConstExprDO StatementSeq END , LOOP StatementSeq END , WITH Guard DO StatementSeq [ELSE StatementSeq] END , EXIT , RETURN [Expr] ]. Case = [CaseLabels ":" StatementSeq]. CaseLabels = ConstExpr [".." ConstExpr]. Guard = Qualident ":" Qualident. ConstExpr = Expr. Expr = SimpleExpr elation SimpleExpr SimpleExpr = "-"Term . Term = Factor . Factor = Designator ("_[ExprList")".html"_;"title="xprList.html"_;"title="("_[ExprList">("_[ExprList")"">xprList.html"_;"title="("_[ExprList">("_[ExprList")".html" ;"title="xprList">("_[ExprList")".html" ;"title="xprList.html" ;"title="(" [ExprList">(" [ExprList")"">xprList.html" ;"title="(" [ExprList">(" [ExprList")""> number , character , string , NIL , Set , "(" Expr ")" , "~" Factor. Set = "". Element = Expr [".." Expr Relation = "=" , "#" , "<" , "<=" , ">" , ">=" , IN , IS. AddOp = "+" , "-" , OR. MulOp = "*" , "/" , DIV , MOD , "&". Designator = Qualident . ExprList = Expr . IdentList = IdentDef . Qualident = [ident "."] ident. IdentDef = ident ["*" , "-"].


Implementations

Oberon-2 compilers maintained by ETH include versions for Windows, Linux, Solaris (operating system), Solaris,
macOS macOS (; previously OS X and originally Mac OS X) is a Unix operating system developed and marketed by Apple Inc. since 2001. It is the primary operating system for Apple's Mac computers. Within the market of desktop and lapt ...
. Th
Oxford Oberon-2 compiler
compiles to native machine code and can use a JIT on Windows, Linux and Mac OS X. It is created/maintained by Mike Spivey and uses the Keiko Virtual Machine. Dr. Michael Spivey
"Specification of Keiko"
Dr. Michael Spivey
"Design overview for OBC: The Keiko Abstract Machine"
quote: "The Oxford Oberon--2 compiler translates source programs into code for a stack-based abstract machine... the Keiko machine"
There is an Oberon-2
Lex Lex or LEX may refer to: Arts and entertainment * ''Lex'', a daily featured column in the ''Financial Times'' Games * Lex, the mascot of the word-forming puzzle video game ''Bookworm'' * Lex, the protagonist of the word-forming puzzle video ga ...
scanner and
Yacc Yacc (Yet Another Compiler-Compiler) is a computer program for the Unix operating system developed by Stephen C. Johnson. It is a Look Ahead Left-to-Right Rightmost Derivation (LALR) parser generator, generating a LALR parser (the part of a co ...
parser Parsing, syntax analysis, or syntactic analysis is the process of analyzing a string of symbols, either in natural language, computer languages or data structures, conforming to the rules of a formal grammar. The term ''parsing'' comes from Lat ...
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. There is a release called '' Native Oberon'' which includes an operating system, and can directly boot on PC class hardware. A .NET implementation of Oberon with the addition of some minor .NET-related extensions has also been developed at ETHZ.
Programmer's Open Workbench
(POW!) is a very simple integrated development environment, which is provided with editor, linker, and Oberon-2 compiler. This compiles to
Windows Windows is a group of several proprietary graphical operating system families developed and marketed by Microsoft. Each family caters to a certain sector of the computing industry. For example, Windows NT for consumers, Windows Server for ser ...
executables. Full
source code In computing, source code, or simply code, is any collection of code, with or without comments, written using a human-readable programming language, usually as plain text. The source code of a program is specially designed to facilitate the w ...
is provided; the compiler is written in Oberon-2. Th
Java to Oberon Compiler
(JOB) was written at the University of Vologda in Russia. It produces object code in the form of Java class files (
bytecode Bytecode (also called portable code or p-code) is a form of instruction set designed for efficient execution by a software interpreter. Unlike human-readable source code, bytecodes are compact numeric codes, constants, and references (norma ...
). Some JOB-specific classes are provided which are Java compatible, but which use a more Oberon-like component hierarchy. Th
Optimizing Oberon-2 Compiler
compiles to C, using the
GNU Compiler Collection The GNU Compiler Collection (GCC) is an optimizing compiler produced by the GNU Project supporting various programming languages, hardware architectures and operating systems. The Free Software Foundation (FSF) distributes GCC as free softwar ...
(GCC) toolchain for program generation.
Oberon Script
is a compiler that translates the full Oberon language into
JavaScript JavaScript (), often abbreviated as JS, is a programming language that is one of the core technologies of the World Wide Web, alongside HTML and CSS. As of 2022, 98% of websites use JavaScript on the client side for webpage behavior, of ...
. The compiler is written in JavaScript and can thus be called from Web pages to process scripts written in Oberon.
XDS Modula2/Oberon2
is a development system by Excelsior LLC, Novosibirsk, Russia. It contains an optimizing compiler for Intel Pentium, or "via-C" translator for
cross-platform software In computing, cross-platform software (also called multi-platform software, platform-agnostic software, or platform-independent software) is computer software that is designed to work in several computing platforms. Some cross-platform software ...
development. Available for Windows and Linux. The compiler is written in Oberon-2 and compiles itself.
Oberon Revival
is a project to bring Oberon 2 and Component Pascal (
BlackBox Component Builder BlackBox Component Builder is an integrated development environment (IDE) optimized for component-based software development developed by a small spin-off company, Oberon microsystems AG, of ETH Zurich in Switzerland. The IDE consists of develop ...
) to Linux and Win32. The Linux port of BlackBox was unavailable before and it originally ran on only Microsoft Windows. XOberon is a
real-time operating system A real-time operating system (RTOS) is an operating system (OS) for real-time applications that processes data and events that have critically defined time constraints. An RTOS is distinct from a time-sharing operating system, such as Unix, which m ...
for PowerPC, written in Oberon-2. The Portable Oberon-2 Compiler (OP2) was developed to port the Oberon System onto commercially available platforms.


Keiko bytecode

Oberon-2 can target the Keiko Virtual machine. For example, like some other language compilers (see
O-code BCPL ("Basic Combined Programming Language") is a procedural, imperative, and structured programming language. Originally intended for writing compilers for other languages, BCPL is no longer in common use. However, its influence is still ...
,
p-code Bytecode (also called portable code or p-code) is a form of instruction set designed for efficient execution by a software Interpreter (computing), interpreter. Unlike Human-readable code, human-readable source code, bytecodes are compact nume ...
, etc.), th
Oxford Oberon-2 compiler
first compiles to an intermediate bytecode (Keiko bytecode) which can be interpreted with a byte-code interpreter or use
just-in-time compilation In computing, just-in-time (JIT) compilation (also dynamic translation or run-time compilations) is a way of executing computer code that involves compilation during execution of a program (at run time) rather than before execution. This may co ...
.


See also

*
A2 (operating system) A2 (formerly named Active Object System (AOS), and then Bluebottle) is a modular, object-oriented operating system, with some unconventional features, including automatic garbage-collected memory management, and a zooming user interface. It was ...
*
Oberon (operating system) The Oberon System is a modular, single-user, single-process, multitasking operating system written in the programming language Oberon. It was originally developed in the late 1980s at ETH Zurich. The Oberon System has an unconventional visual text ...
*
Oberon (programming language) Oberon is a general-purpose programming language first published in 1987 by Niklaus Wirth and the latest member of the Wirthian family of ALGOL-like languages (Euler, ALGOL W, Pascal, Modula, and Modula-2). Oberon was the result of a concentrate ...


References


Evolution of Oberon and Oberon-2

* "
Oberon Language Genealogy Tree
'" maintained at
ETHZ (colloquially) , former_name = eidgenössische polytechnische Schule , image = ETHZ.JPG , image_size = , established = , type = Public , budget = CHF 1.896 billion (2021) , rector = Günther Dissertori , president = Joël Mesot , a ...
* "Second International Modula-2 Conference", September 1991.


Detailed papers


From Modula to Oberon
Wirth (1990)
Programming in Oberon - A derivative of Programming in Modula-2
Wirth (1982)
The Programming Language Oberon
Wirth (1990) * tp://ftp.ethoberon.ethz.ch/Oberon/OberonV4/Docu/Oberon2.Report.ps.gz Oberon 2 Report
The Programming Language Oberon-2
H. Mössenböck, N. Wirth, Institut für Computersysteme, ETH Zurich, January 1992 an
Structured Programming
(1991) 12(4): 179-195.


Books




Object-Oriented Programming in Oberon-2
Hanspeter Mössenböck (1994). (Available fro
Johannes Kepler University
as PDF with the friendly permission of Springer-Verlag)
Design Patterns in Oberon-2 and Component Pascal

Project Oberon. The design of an Operating System and Compiler
Niklaus Wirth & Jürg Gutknecht (2005)
Project Oberon. The design of an Operating System and Compiler
Niklaus Wirth & Jürg Gutknecht (2013)


External links

* , ETH Zürich
Oberon Reference page at ETH Zürich




* ftp://ftp.inf.ethz.ch/pub/Oberon/
The Oberon-2 Reflection Model and its Applications
{{Wirth Modula programming language family Object-oriented programming languages Oberon programming language family Programming languages created in 1991