in Academic, Coding

Thomas’ Functional Interpreter

I just finished a small functional interpreter for an university course. To be precise, the interpreter itself is not functional, but it understands a functional, LISP-like language/syntax. The whole project is written in Java 7 and provides an interface to all Java classes on the class-path, too.

I also tried to create a small IDE in Swing. I built an editor with syntax-highlighting and code-completion (thanks to the RSyntaxTextArea project), an environment inspector and a small debugger to keep track of the stack. Take a look at it.

I called it ThoFu for Thomas’ Functional Interpreter. I think it teats good… You can get some brief impressions from the slideshow below.

The whole project is open, you can find it as an Eclipse project on my Bitbucket account. It contains the actual code, all libraries, screen-shots, unit tests and (of course) some documentation like UML diagrams. Here are the links to the GIT repository:


Here is the executable JAR-file (Note: You need Java 7). Just download it, double-click it and go-ahead:

Executable program: ThoFu Interpreter.jar

And this is how it goes. First a simple “hello world” program:

Now, a more sophisticated one. Here’s a quicksort-algorithm for my interpreter. It contains some user-defined functions, multi-line statements and some comments.

And this is how the Java API works. The code will create a JFrame with a JButton and a JLabel. When you press the button, the listener will change the text of the label from “click me” to “hello“. The syntax is inspired by the Java Dot Notation by Peter Norvig. I used the Apache Commons Lang library for the reflection-tricks to load class and so on.

You can just copy and paste the code snippets into the editor or save them as common text files and open them. They are also in the repository. The JUnit tests contain many more examples as well.

For those who are interested in the topic, you can find my resources (libraries, tool and literature) in the Read-Me.

Best regards,
Thomas Uhrig

Write a Comment