I want to make an interpreter of a very simple language for practice. When I say simple I don't mean easy to use, I mean simple. Brainf**k is a good example of a language I want. I already have made a brainf**k interpreter in python (which is the language I would be using to write the interpreter). I would appreciate any suggestions of simple languages.
Note: I don't want to make a compiler! I want to make an interpreter.
Edit: I want a language where all features are defined and not to numerous or advanced. For example: brainf**k has exactly eight symbols that are easy to parse.
And I want to use python to make the interpreter (using PLY), not C or something else.
views:
986answers:
13Didn't Bill Gates write a Basic interpreter ?
There are also many examples of Basic Interpreters out there.
You could try something like a simplified LISP interpreter.
While LISP is a pretty big language, it's pretty simple to write something that can parse and execute LISP like S-expressions. Once you have that, you could extend your interpreter to support whatever other features of the language you find the most interesting.
If you're looking to implement a complete language, you might want to try Scheme. It's similar to LISP and you can also start by writing a simple interpreter for S-expressions. But, it's a much smaller language.
Logo is a fairly simple beginners language that looks like it would be reasonable to build an interpreter for.
Small subsets of Lisp or Scheme are easy to build interpreters for as well, if you are familiar with functional programming.
Another option is to write your own language and build an interpreter for it. That gives you excellent experience.
I would say Brainf**k is actually your best bet: it's only got six eight very simple commands, and the entire source file can be parsed in a single run on-the-fly.
[Edit] Since you've already written a Brianf**k interpreter, your next best bet is interpreting some simple assembly language, such as PDP-8, which only has about two dozen instructions.
I recently did this for Scheme by following a great set of blog posts by Peter Michaux. you can find them here http://peter.michaux.ca/articles/scheme-from-scratch-introduction
the series covers just about everything you need to know while leaving enough out to make it interesting (if you get stuck you can always look at the authors code).
You dont even really need to know scheme all that well to get started with this..
I would say Forth is a very easy language to interpret. I worked on a project to have a bootsector(512 bytes) that was a Forth Interpreter.. I never got further than a simple RPN calculator with peek/poke commands(I had about 150 bytes left, but I got bored with it)
The language is very simple though and should be trivial to write an interpreter for
Invent your own language. Then you can learn some basic language design ideas at the same time as you learn about implementation techniques. And you can avoid getting bogged down with some language feature that is too gnarly ... or too tedious ... to be fun.
PostScript is a surprisingly pleasant language to write an interpreter for. Leave out all the graphics operators and you have a weird little stack-based language that operates on strings, numbers, tables, and arrays. Kind of like Forth but with data structures and (dynamic) types. It would be fun to write the interpreter in Python.
Don't take me too serious, but the 'h' language is a very simple one specified by Jon Skeet. The full reference manual of the language can be found in this answer
Scheme and Lisp are quite good, but still it can be made much easier. Look at the SKI calculus. It has only three concepts and it is possible to write any algorithm in it. It is and equivalent of untyped lambda calculus, which is theoretical base for interpreting functional programs. Also the meaning of those three concepts is so easy, that you could implement them just by using regexp one liners.
Take a look at an already implemented simplified scheme in Python lis.py by Peter Norvig. It is excellent tutorial and demonstration in only 90 lines of code. Several days ago he wrote a more complete version (How to Write a (Lisp) Interpreter (in Python))
Write a programmable calculator. You can implement a subset of an existing one (say, TI-59), or create your own.