# How to write a toy interpreter

**URL:** <https://www.ruby-forum.com/t/how-to-write-a-toy-interpreter/91415>\
**Category:** Ruby\
**Created:** [April 8, 2007, 7:38pm UTC](https://www.ruby-forum.com/t/how-to-write-a-toy-interpreter/91415 "2007-04-08T19:38:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pedro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/919ad9/32.png) [@pedro](https://www.ruby-forum.com/u/pedro)\
**Post date:** [April 8, 2007, 7:38pm UTC](https://www.ruby-forum.com/t/how-to-write-a-toy-interpreter/91415/1 "2007-04-08T19:38:58Z")

</div>

Hi,

I was reading today this post [1], and i would like to write my own  
toy interpreter. The simplest example possible (with or without ruby).

Can anyone recommend me some start points ? (URLs, tutorials, or books )

Thanks.

[1] : [http://code.google.com/p/cat-language/wiki/HowTheInterpreterWorks](http://code.google.com/p/cat-language/wiki/HowTheInterpreterWorks)

## –

Pedro Del G.

Email : removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![pedro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/919ad9/32.png) [@pedro](https://www.ruby-forum.com/u/pedro)\
**Post date:** [April 8, 2007, 9:12pm UTC](https://www.ruby-forum.com/t/how-to-write-a-toy-interpreter/91415/2 "2007-04-08T21:12:10Z")

</div>

On Mon, Apr 09, 2007 at 02:37:46AM +0900, Pedro Del G. wrote:

> I was reading today this post [1], and i would like to write my own  
> toy interpreter. The simplest example possible (with or without ruby).
> 
> Can anyone recommend me some start points ? (URLs, tutorials, or books )

An excellent book for everything about language parsing and code  
generation  
is “Compilers: Principles, Techniques and Tools”

> **[Compilers: Principles, Techniques, and Tools](https://en.wikipedia.org/wiki/Compilers:_Principles,_Techniques,_and_Tools)**
>
> Compilers: Principles, Techniques, and Tools is a computer science textbook by Alfred V. Aho, Monica S. Lam, Ravi Sethi, and Jeffrey D. Ullman about compiler construction for programming languages. First published in 1986, it is widely regarded as the classic definitive compiler technology text.
> It is known as the Dragon Book to generations of computer scientists as its cover depicts a knight and a dragon in battle, a metaphor for conquering complexity. This name can also refer to Aho and Ullman...

---

<div class="post-metadata">

**Author:** ![pedro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/919ad9/32.png) [@pedro](https://www.ruby-forum.com/u/pedro)\
**Post date:** [April 8, 2007, 11:36pm UTC](https://www.ruby-forum.com/t/how-to-write-a-toy-interpreter/91415/3 "2007-04-08T23:36:28Z")

</div>

A toy interpreter is part of the test suite for Dhaka (a parser  
generator -  
[http://dhaka.rubyforge.org](http://dhaka.rubyforge.org)). There’s even a page documenting the  
interesting  
bits:

[http://dhaka.rubyforge.org/chittagong.html](http://dhaka.rubyforge.org/chittagong.html)

The whole interpreter is about 300 lines of code.

Mushfeq.
