Oberon-2
Encyclopedia
Oberon-2 is an extension of the original Oberon
Oberon (programming language)
Oberon is a programming language created in 1986 by Professor Niklaus Wirth and his associates at ETH Zurich in Switzerland. It was developed as part of the implementation of the Oberon operating system...

 programming language
Programming language
A programming language is an artificial language designed to communicate instructions to a machine, particularly a computer. Programming languages can be used to create programs that control the behavior of a machine and/or to express algorithms precisely....

 that adds limited reflection
Reflection (computer science)
In computer science, reflection is the process by which a computer program can observe and modify its own structure and behavior at runtime....

 and object-oriented
Object-oriented programming
Object-oriented programming is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their interactions – to design applications and computer programs. Programming techniques may include features such as data abstraction,...

 programming facilities, open arrays as pointer base types, read-only field export and reintroduces the FOR loop from Modula-2.

It was developed in 1991 at ETH Zurich
ETH Zurich
The Swiss Federal Institute of Technology Zurich or ETH Zürich is an engineering, science, technology, mathematics and management university in the City of Zurich, Switzerland....

 by Niklaus Wirth
Niklaus Wirth
Niklaus Emil Wirth is a Swiss computer scientist, best known for designing several programming languages, including Pascal, and for pioneering several classic topics in software engineering. In 1984 he won the Turing Award for developing a sequence of innovative computer languages.-Biography:Wirth...

 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, and is fully compatible with it. Oberon-2 was a redesign of Object Oberon
Object Oberon
Object Oberon is a programming language which is based on the Oberon programming language with features for object-oriented programming. Oberon-2 was essentially a redesign of Object Oberon.-References:...

.

Oberon-2 inherited limited reflection and single inheritance ("type extension") without interfaces or mixins from Oberon, but added efficient virtual methods ("type bound procedures"). Method calls were resolved at run-time using C++
C++
C++ is a statically typed, free-form, multi-paradigm, compiled, general-purpose programming language. It is regarded as an intermediate-level language, as it comprises a combination of both high-level and low-level language features. It was developed by Bjarne Stroustrup starting in 1979 at Bell...

-style virtual method tables.

Compared to fully object-oriented programming languages like Smalltalk
Smalltalk
Smalltalk is an object-oriented, dynamically typed, reflective programming language. Smalltalk was created as the language to underpin the "new world" of computing exemplified by "human–computer symbiosis." It was designed and created in part for educational use, more so for constructionist...

, in Oberon-2 basic types are not objects, classes are not objects, many operations are not methods, there is no message passing
Message passing
Message passing in computer science is a form of communication used in parallel computing, object-oriented programming, and interprocess communication. In this model, processes or objects can send and receive messages to other processes...

 (to a certain extent it can be emulated 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 with object-oriented programming languages, duck typing is a style of dynamic typing in which an object's current set of methods and properties determines the valid semantics, rather than its inheritance from a particular class or implementation of a specific interface...

 like in Smalltalk
Smalltalk
Smalltalk is an object-oriented, dynamically typed, reflective programming language. Smalltalk was created as the language to underpin the "new world" of computing exemplified by "human–computer symbiosis." It was designed and created in part for educational use, more so for constructionist...

/Ruby
Ruby (programming language)
Ruby is a dynamic, reflective, general-purpose object-oriented programming language that combines syntax inspired by Perl with Smalltalk-like features. Ruby originated in Japan during the mid-1990s and was first developed and designed by Yukihiro "Matz" Matsumoto...

, and it's not possible to define interfaces like in Java
Java (programming language)
Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities...

). Oberon-2 does not support encapsulation at object/class level, but modules can be used for this purpose.

Reflection in Oberon-2 does not use meta-objects, but simply reads from type descriptors compiled 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 level. It could therefore be implemented almost entirely at library level, without changing the language code. Indeed, ETH Oberon makes use of language-level and library-level reflection capabilities extensively.

Oberon-2 provides built-in run-time support for garbage collection 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/C++. Separate compilation using symbol files and name-spaces via the module architecture ensure quick rebuilds since only modules with changed interfaces need to be recompiled.

Example Oberon-2 code

The following Oberon-2 code would implement a very minimal list class:


MODULE Lists;

(*** declare global constants, types and variables ***)

TYPE
List* = POINTER TO ListNode;
ListNode = RECORD
value : INTEGER;
next : List;
END;

(*** declare procedures ***)

PROCEDURE (l : List) Add* (v : INTEGER);
BEGIN
IF l = NIL THEN
NEW(l); (* create record instance *)
l.value := v
ELSE
l.next.Add(v) (* recursive call to .add(n) *)
END
END Add;

PROCEDURE (l : List) Get* : INTEGER;
VAR
v : INTEGER;
BEGIN
IF l = NIL THEN
RETURN 0 (* .get must always return an INTEGER *)
ELSE
v := l.value; (* this line will crash if l is NIL *)
l := l.next;
RETURN v
END
END Get;

END Lists.

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 previously 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.

Run-time 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 run-time.

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
In programming language theory, subtyping or subtype polymorphism is a form of type polymorphism in which a subtype is a datatype that is related to another datatype by some notion of substitutability, meaning that program constructs, typically subroutines or functions, written to operate on...

 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.


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
ALGOL is a family of imperative computer programming languages originally developed in the mid 1950s which greatly influenced many other languages and became the de facto way algorithms were described in textbooks and academic works for almost the next 30 years...

 - Pascal
Pascal (programming language)
Pascal is an influential imperative and procedural programming language, designed in 1968/9 and published in 1970 by Niklaus Wirth as a small and efficient language intended to encourage good programming practices using structured programming and data structuring.A derivative known as Object Pascal...

 - Modula-2
Modula-2
Modula-2 is a computer programming language designed and developed between 1977 and 1980 by Niklaus Wirth at ETH Zurich as a revision of Pascal to serve as the sole programming language for the operating system and application software for the personal workstation Lilith...

 - Oberon - Component Pascal
Component Pascal
Component Pascal is a programming language in the tradition of Niklaus Wirth's Pascal, Modula-2, Oberon and Oberon-2. It bears the name of the Pascal programming language but is incompatible with it. Instead, it is a minor variant and refinement of Oberon-2, designed and supported by a small ETH...

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, 1993) using only 33 grammatical productions in the extended Backus–Naur form
Extended Backus–Naur form
In computer science, Extended Backus–Naur Form is a family of metasyntax notations used for expressing context-free grammars: that is, a formal way to describe computer programming languages and other formal languages. They are extensions of the basic Backus–Naur Form metasyntax notation.The...

, as shown below.


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 [" * " | "-"].

Implementations

Oberon-2 compilers maintained by ETH
Eth
Eth is a letter used in Old English, Icelandic, Faroese , and Elfdalian. It was also used in Scandinavia during the Middle Ages, but was subsequently replaced with dh and later d. The capital eth resembles a D with a line through the vertical stroke...

 include versions for Windows, Linux, Solaris, Mac OS X.

There is an Oberon-2 Lex
Lex programming tool
Lex is a computer program that generates lexical analyzers . Lex is commonly used with the yacc parser generator. Lex, originally written by Mike Lesk and Eric Schmidt, is the standard lexical analyzer generator on many Unix systems, and a tool exhibiting its behavior is specified as part of the...

 scanner and Yacc
Yacc
The computer program yacc is a parser generator developed by Stephen C. Johnson at AT&T for the Unix operating system. The name is an acronym for "Yet Another Compiler Compiler." It generates a parser based on an analytic grammar written in a notation similar to BNF.Yacc used to be available as...

 parser 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
Native Oberon
Native Oberon or ETHNO, is the version of the Oberon operating system which runs on x86 PC hardware. It has minimal hardware requirements...

which includes an operating system, and can directly boot on PC class hardware.

A .NET
.NET Framework
The .NET Framework is a software framework that runs primarily on Microsoft Windows. It includes a large library and supports several programming languages which allows language interoperability...

 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
Microsoft Windows
Microsoft Windows is a series of operating systems produced by Microsoft.Microsoft introduced an operating environment named Windows on November 20, 1985 as an add-on to MS-DOS in response to the growing interest in graphical user interfaces . Microsoft Windows came to dominate the world's personal...

 executables. Full source code is provided - the compiler is written in Oberon-2.

The 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
Bytecode, also known as p-code , is a term which has been used to denote various forms of instruction sets designed for efficient execution by a software interpreter as well as being suitable for further compilation into machine code...

). Some JOB-specific classes are provided which are Java compatible, but which use a more Oberon-like component hierarchy.

The Optimizing Oberon-2 Compiler compiles to C, using the gcc toolchain for program generation.

Oberon Script is a compiler that translates the full Oberon language into JavaScript
JavaScript
JavaScript is a prototype-based scripting language that is dynamic, weakly typed and has first-class functions. It is a multi-paradigm language, supporting object-oriented, imperative, and functional programming styles....

. The compiler proper is written in JavaScript and can therefore be called from Web pages in order to process HTML script
HTML scripting
The W3C HTML standard includes support for client-side scripting.It defines how locally executable scripts may be used in a web page.A particular client-side application, such as a web browser, may support several script languages....

  sections 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 development. Available for Windows and Linux. The compiler is written on Oberon-2 and compiles itself.

Oberon Revival is a project to bring Oberon 2 and Component Pascal (blackbox) to Linux and Win32. The Linux port of blackbox was not available before and it originally ran only on Microsoft Windows.

Evolution of Oberon and Oberon-2


Detailed papers

  • [ftp://ftp.inf.ethz.ch/pub/software/Oberon/OberonV4/Docu/ModToOberon.ps.gz From Modula-2 to Oberon] Wirth (1988)
  • [ftp://ftp.inf.ethz.ch/pub/software/Oberon/OberonV4/Docu/OberonReport.ps.gz The Programming Language Oberon] Wirth (1988)
  • Programming in Oberon - A derivative of Programming in Modula-2 Wirth (1982)
  • [ftp://ftp.inf.ethz.ch/pub/software/Oberon/OberonV4/Docu/Oberon2.Report.ps.gz Oberon 2 Report]
  • [ftp://ftp.inf.ethz.ch/pub/software/Oberon/OberonV4/Docu/Oberon2.Differences.ps.gz Differences between Oberon and Oberon-2] Mössenböck and Wirth (1991)
  • The Programming Language Oberon-2 H. Mössenböck, N. Wirth, Institut für Computersysteme, ETH Zürich (ETHZ), January 1992.
  • What's New in Component Pascal (Changes from Oberon-2 to CP), Pfister (2001)

Books


External links

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK