Skip to content

saulfield/interpreter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Overview

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

Example

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

Run it

Interpreter

pip install parsley

python sol.py [file]

Running with no file will drop into REPL mode.

AST Visualizer

Download Graphviz

Get the Python Graphviz interface:

pip install graphviz

Run:

python visualize.py [file]

AST Image

References

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.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages