This is an interpreter for a simple programming language written for educational purposes. The goal was to keep things as minimal as possible to allow for quick prototyping.
The combination of Python + OMeta is very expressive, and was a great fit for this project. The total code is around 250 lines (55 of OMeta).
func fib(n)
{
if (n < 2) return n;
return fib(n - 2) + fib(n - 1);
}
print "Fibonacci:";
for (var i = 0; i < 10; i = i + 1) {
print fib(i);
}
Output:
Fibonacci:
0
1
1
2
3
5
8
13
21
34
pip install parsley
python sol.py [file]
Running with no file will drop into REPL mode.
Get the Python Graphviz interface:
pip install graphviz
Run:
python visualize.py [file]
This is the meta-language used for the parser. It's basically a souped-up PEG. Alessandro Warth's thesis is probably the best place to read about it.
An implementation of OMeta in Python.
Excellent introductory book on implementing interpreters. This language and interpreter are strongly inspired by jlox.