views:

986

answers:

13

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.

+1  A: 

Didn't Bill Gates write a Basic interpreter ?

There are also many examples of Basic Interpreters out there.

Romain Hippeau
+16  A: 

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.

dmcer
+2  A: 

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.

Stephen
Log is not really a simple language. Log is a lot more than turtle graphics. In fact, the nearest neighbor of logo is lisp.
John Smith
+4  A: 

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.

BlueRaja - Danny Pflughoeft
I'm assuming you mean brAInf**k? Brianf**k sounds like something altogether different.
Adam Robinson
I said in the question that I had already made a brainf**k interpreter. And if you mean symbols when you say commands there are actually eight: ><+-.,[]
None
@None: Whether you yourself have already done it has no bearing on whether Brainfuck is the easiest language to write an interpreter for. That would just mean you've already written an interpreter for the easiest language.
Chuck
In the May, 2008 issue of Python magazine, I wrote an article on creating a BF interpreter using pyparsing, and added a twist at the end to turn the interpreter into a compiler. Given the current state of PyMag, I'm not sure how easy it is to get back-issues though.
Paul McGuire
+8  A: 

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

luke
+10  A: 

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

Earlz
+6  A: 

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.

Stephen C
If your goal is to practice writing an interpreter, having to come up with your own language seems counter-productive. That's a lot to think about at once.
musicfreak
@musicfreak - nonsense! Everyone has a rough idea what an identifier should look like, a declaration, an expression, an if statement, a (built-in) function call. And bingo, that is a toy language you can write a toy interpreter for!
Stephen C
Eh, true, but then you might as well use one of the hundreds of programming languages already available. :)
musicfreak
Coming up with your own language means you won't get bogged down in the details of an existing language's syntax.
kyoryu
@kyoryu - precisely! That's the point I'm trying to make.
Stephen C
Well you don't have to follow the language you choose by the book. But I guess if you don't then you're making up your own language, so ultimately you're right. :)
musicfreak
+2  A: 

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.

Norman Ramsey
+3  A: 

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

Time Machine
I came here just to post this....
kyoryu
@kyoryu, it's community wiki so everyone posted it ;)
Time Machine
+1  A: 

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.

Gabriel Ščerbák
I combinator is redundant. S and K are enough for a Turing-complete language.And there is a good example of such a language - Unlambda:http://en.wikipedia.org/wiki/Unlambda
SK-logic
@SK-logic Ok, if you wanna get super-simple, look at the <a href="http://en.wikipedia.org/wiki/Iota_and_Jot">Iota and Jot</a> which has one universal combinator.
Gabriel Ščerbák
A: 

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

boskom
A: 

Write a programmable calculator. You can implement a subset of an existing one (say, TI-59), or create your own.

ern0