How to Write an Interpreter in One Day
rpal.sourceforge.net
rpal.sourceforge.net
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?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.
(define my-interpreter eval)