Lisp Interpreter

I’ve begun work (say… about 8pm last night) on a piece of software that even after one day, I’m very proud of. It’s a Lisp interpreter.

Lisp, as some of you might know, has an incredibly simple syntax that makes it great for writing interpreters for. So that’s what I’ve been doing. At the moment, my software can take an S-expression from either stdin or a file, and create a syntax tree. It can also print out said syntax tree into the original S-expression.

I’m now fleshing out the details on how I want the core of the interpreter, the Eval() routine, to work. I’ve decided I want to use a Forth-like system of primitive and non-primitive words. So identifiers in my symbol table will point to either a syntax tree, which can then be Eval()ed further, or to a machine-code routine.

The hard part about doing things like this is getting machine code loaded into the interpreter system. I’ve come up with a few methods to do this:

  1. A dynamically linked library (.so / .dll) with symbol table entries pointing to their addresses within this library. If I do it this way, I can create a new library of routines without having to create a new interpreter binary. The only problem is, I don’t know how to create dynamic libraries.
  2. Vaguely the same idea as a dynamically linked library, but not using the proper method. That is, compile down to machine code and store the routine in a file with a format of my devising. I think I could do this, but I can’t remember from my operating system knowledge whether it will let me execute code in a data section (which is where the loaded file would be stored).
  3. Compiling the library right into the interpreter. I don’t really want to do this, but I will if I can’t get the other two to work. It is however, the easiest.

I’m looking for people’s input on how they think I should do this. I really have no idea. I can see a lot of flaws in all three methods. So maybe I am missing something.

I’ve learned a lot already. Namely:

  1. If you’re writing function that returns a linked list and it isn’t working, make sure return(List); is written in the function somewhere.
  2. Segmentation faults are never fun. Neither are syntax errors.
  3. English Breakfast tea along with Breakaway chocolate is great. But not in the same cup at once.

Hopefully I can decide what I want to do. If I can, expect a primitive release sometime in the next week or so.

Liked this? Here's some more:

  • No Related Posts! How sad!