/noct

nickelsworth oberon-07 compiler / transpiler

Primary LanguageGAPOtherNOASSERTION

noct : the Nickelsworth Oberon Compiler/Transpiler

Copyright (c) 2013 Michal J. Wallace Available for use under the MIT/X11 License. (see file:LICENSE)

Overview : A Source-to-Source compiler for Oberon 07

noct is a transpiler. It translates Oberon-07 code to other programming languages, like java or pascal.

The hard part of compilation is done by the target compilers, and the parser relies on (ANTLR3), so there is very little code to noct itself.

The main files are:

Oberon07.g
the grammar definition. ANTLR uses this to generate java code for a parser, which in turn builds up an abstract syntax tree of the input.
OberonEmitter.g
a “tree grammar”. ANTLR uses tree grammars to generate programs that walk the abstract syntax tree and process it in various ways. In this case, the process simply involves generating code.

The targets directory contains the templates for each target language. These are created with StringTemplate.

Since the grammar and emitter are complete, and reusable, most of the work to be done here involves creating and updating templates. In addition, each target language requires the implementation of a small library, to provide the handful of primitives. See Section 10.2 in the language report for details.

About the source language: Oberon 07

Oberon is a small procedural programming language created at ETH Zurich (the Swiss Federal Institute of Technology), primarily by Dr Niklaus Wirth, who also created the languages Pascal and Modula.

Oberon is a successor to these languages, first created in 1986 as part of Project Oberon, a (successful!) attempt to create a complete programming language and operating system from scratch.

Since then, there have been various incarnations of the Oberon language. Oberon 07 is the latest, documented in the Oberon07.Report.pdf (also readable online at google docs). The “07” is short for 2007, though the language report was revised again in 2011.

Dr Wirth seems to have spent his career working pursuing simplicity. While other languages sprout new features as time goes by, Wirth has done his best to remove them.

What remains is a very small, practical, imperative language.

Features of Oberon-07:

  • clear, readable syntax
  • modules (for reuse and speedy compilation)
  • garbage collection
  • type extension (inheritance)

The project Oberon book (and other publications related to Oberon) are now out of print, but the authors have been generous enough to release them for free in PDF form. You can find them at the Oberon bibliography.

There are also a number of Oberon Articles at Dr Wirth’s home page.

Target Languages

noct can translate Oberon-07 code to the following languages:

targetstatusnotes
Oberonworking(?)acts as a source code formatter
javaworking(?)
free pascalpartial
retroplannedbecause of its excellent virtual machine

Requirements

Note: Java is the only real requirement. The others are optional, or used only for testing specific backends.

java
The parser is written with ANTLR3, and the templates are made with StringTemplate. These tools are both written in Java, and there is a small amount of Java code holding the two together.

The ANTLR 3.4 jar files are included here in the jars/ directory, so you only need to install java.

make
Not strictly required, but there is a makefile used for various project management tasks.
free pascal
For testing the pascal backend, and for compiling the pascal port of ngaro for use with the retroforth backend.

Project Status

@tangentstorm wrote the code for noct in April 2012 as a prototype, then shifted focus to the virtual machine and a prototype PL/0-to-retroforth compiler in python.

In the time since this code was first written, new versions of ANTLR and StringTemplate were released. While the new versions are quite nice, they are a complete rewrite with a much different feature set, and there is (currently) no plan to upgrade this codebase to support them.

The code for noct was released as open source on Jan 18, 2013, after a revival of the #oberon channel on irc.freenode.net.