168 karma · joined July 24, 2014
Single pass compilers have their advantages.
I thought we cannot have cycles in Go packages. The Go spec says "The importing of packages, by construction, guarantees that there can be no cyclic initialization dependencies." What am I missing?
The Oberon0 language, described in the compiler book, is just a toy to illustrate basic compiler techniques. The full Oberon language is a simple but powerful language, that inspired Go.
To showcase Wirth's approach, I wrote a self hosted Oberon compiler for the JVM: https://github.com/lboasso/oberonc
The compiler can also be used to compile and run the source code of Oberon0 provided in the book, all you need is a JVM installed.
For example the Oberon definition below:
DEFINITION MathUtil;
PROCEDURE ln(x : REAL) : REAL;
END MathUtil.
exposes the Java MathUtil.ln() static method: public class MathUtil {
public static float ln(float x) {
return (float) java.lang.Math.log(x);
}
}
A client module can use now the Java implementation of ln: MODULE Client;
IMPORT MathUtil;
VAR x: REAL;
BEGIN
x: = MathUtil.ln(2.0);
MathUtil.ln()
END Client;
For a complete example see https://github.com/lboasso/oberonc/tree/master/examples/fernThis includes my own Oberon-07 compiler targeting the JVM: https://github.com/lboasso/oberonc
You can run Project Oberon with this emulator (pre-built binaries available): https://github.com/pdewacht/oberon-risc-emu
The book is freely available here: http://people.inf.ethz.ch/wirth/CompilerConstruction/index.h...
For a more comprehensive example, you can have a look at my compiler for the full Oberon language targeting the JVM. It is based on the principles of that book: https://github.com/lboasso/oberonc
If enough people are interested in this project, I am planning to write a blog post series dissecting and explaining the code base (given the small size it should be feasible). Another idea is to port the whole Project Oberon to the JVM like this project https://github.com/schierlm/OberonEmulator, with the difference that the code will run at full speed since there is no emulation involved.
[1] https://github.com/sparkgs/sparkgs/blob/master/pom.xml [2] http://sparkgs.github.io/
ex. var strings = { "red", "green", "blue" } //ArrayList
var strings2 : LinkedList<String> = { "red", "green", "blue" }