
How to Write an Interpreter in One Day - pauldwoolcock
http://rpal.sourceforge.net/oneday.html
======
chrisdone
While we're showing off pointless interpreters, here's a simple currying lazy
lambda-calculus-like language with pattern-matching-based choice:
<http://hpaste.org/fastcgi/hpaste.fcgi/view?id=24800>

It achieves recursive definitions using fix (teh Y combinator!! \f.(\x.f (x
x)) (\x.f (x x))). Binding variables is done with lambda abstractions. Pattern
matching is done with (foo).

    
    
        fix (\a.\(0) n.add n 1;m n.(\(true).a (sub m 1) 1;(false).a (sub m 1) (a m (sub n 1))) (eq n 0)) 3 2
    
    

It works out the Ackermann of 3 and 2 (29) in about the same time normal
Haskell does in GHCi. Isn't it just a joy to read?

------
stcredzero
Such a toy language isn't pointless. Everyone needs to implement a language,
even a toy one. If one is working in C, one should learn assembly and
implement a toy C-like language. This is really a necessity, so one has a
working knowledge of what happens under the covers when they compile a
program.

Such a freely available kit with a toy assembly language, a provided lexical
analyser, and a toy grammar with no semantics would be a great boon to the
programming community at large, especially if the project could be completed
by the student in one weekend. Countless lightbulbs going off in programmer's
heads all around the world would result.

The one day interpreter project should be done by everyone who wants to become
uber-devs in a language like Python or Ruby.

------
arethuza
Choosing a postfix syntax stack oriented language can make things lot easier -
at least for the interpreter developer, if not for anyone trying to program in
your language.

------
RiderOfGiraffes
He says Yacc and Lex suck, but didn't mention ANTLR which, I'm told, sucks a
lot less. Does anyone here have experience enough to compare and contrast?

~~~
plesn
There are also parser combinator libraries in several languages. Haskell's
Parsec is quite a pleasure to work with. Even if the one in your language is
quite beta it should be enough for such a toy project.

------
antirez
Related: <http://antirez.com/page/picol>

------
kunjaan
#lang scheme

(define my-interpreter eval)

