# Beggining the compiler journey

**URL:** <https://www.ruby-forum.com/t/beggining-the-compiler-journey/155567>\
**Category:** Ruby\
**Created:** [December 13, 2008, 5:06pm UTC](https://www.ruby-forum.com/t/beggining-the-compiler-journey/155567 "2008-12-13T17:06:11Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![rafaelrosafu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/59ef9b/32.png) [@rafaelrosafu](https://www.ruby-forum.com/u/rafaelrosafu)\
**Post date:** [December 13, 2008, 5:06pm UTC](https://www.ruby-forum.com/t/beggining-the-compiler-journey/155567/1 "2008-12-13T17:06:11Z")

</div>

Hi,

I’ve being working with computer’s for 13+ years, but I classify myself  
as a good high-level (as in high abstraction) programmer, with a  
business logic focus. As such I don’t have any relevant knowledge about  
low level stuff, except the big picture ideas like what’s a compiler,  
bytecode, process, threads, etc, I never studied the actual  
implementation of those things.

Now I wish to take a dive and learn this stuff, but I’m having a hard  
time finding a good global guide. I’m looking for a book, a tutorial, or  
anything like that, that can explain the differences between the  
architecture for a language used with a VM and another without, what’s  
the impact of these choices when building a compiler, how low level  
memory management works, what’s the current trend, etc.

I’ve navigated Wikipedia and Google, and started to read Jack Crenshaw’s  
compiler tutorial, and though I like the hands-on approach (specially  
the use of Pascal), and think that’s it’s a nice first-timer stuff, it  
assumes the reader knows how to read assembly language and how to work  
with stack stuff. Another thing is that it’s not designed to work with  
prÃ©-8080 processors and I’m pretty sure there’s a world of differences  
between that and current technologies, like multi-core processors.

I’ve also started to read Niklaus Wirth “Compiler Construction” and it’s  
really, really nice, but it also assumes the reader knows a lot of stuff  
that I don’t. I can understand the basics of it, but can’t understand  
the details, so I need more info.

Anyway, I’m looking for a good guide to help me find my way. I’m not  
planning to become a compiler expert or really understand the complex  
math behind all of it, I just want to have a geek hobby and have a  
understanding of what’s going on behind the curtains. If anyone can  
recommend me a good companion for Wirth’s work, I’d be very happy. Stuff  
in Portuguese, French or Spanish, and of course English, is welcome.

By the way, I’m asking this kind of stuff on a Ruby list because I want  
to play with Ruby language stuff, so I thought it would be better to be  
around the appropriate folks. I’ve even downloaded Ruby’s source but I  
have no idea of where to start reading it 🙂

Thanks a lot,  
Rafael.

---

<div class="post-metadata">

**Author:** ![rafaelrosafu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/59ef9b/32.png) [@rafaelrosafu](https://www.ruby-forum.com/u/rafaelrosafu)\
**Post date:** [December 13, 2008, 10:29pm UTC](https://www.ruby-forum.com/t/beggining-the-compiler-journey/155567/2 "2008-12-13T22:29:39Z")

</div>

hi rafael!

Rafael R. [2008-12-13 16:58]:

> Now I wish to take a dive and learn this stuff, but I’m having a  
> hard time finding a good global guide. I’m looking for a book, a  
> tutorial, or anything like that, that can explain the differences  
> between the architecture for a language used with a VM and  
> another without, what’s the impact of these choices when building  
> a compiler, how low level memory management works, what’s the  
> current trend, etc.  
> maybe “Programming Language Pragmatics” by Michael L. Scott can give  
> you some hints. it might not be a perfect fit for your needs,  
> though. just thought i’d throw it in… i’m coming from a totally  
> different background but i really enjoy reading it.

[http://www.cs.rochester.edu/~scott/pragmatics/](http://www.cs.rochester.edu/~scott/pragmatics/)

> By the way, I’m asking this kind of stuff on a Ruby list because  
> I want to play with Ruby language stuff, so I thought it would be  
> better to be around the appropriate folks. I’ve even downloaded  
> Ruby’s source but I have no idea of where to start reading it 🙂  
> the README.EXT file might be a good starting point.

cheers  
jens

---

<div class="post-metadata">

**Author:** ![rafaelrosafu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/59ef9b/32.png) [@rafaelrosafu](https://www.ruby-forum.com/u/rafaelrosafu)\
**Post date:** [December 14, 2008, 12:49am UTC](https://www.ruby-forum.com/t/beggining-the-compiler-journey/155567/3 "2008-12-14T00:49:40Z")

</div>

Hi Jens.

Thanks for the link, I’ve read the Preface and the took a peek on the  
index and it seems to be very very close to what I’m looking for, thanks  
a lot.

As for the readme, I did read it, but it didn’t explain how to  
understand how the compiler code is organized, and I didn’t expect it to  
do so 🙂 Without understanding how things should be arranged is very  
hard to look at all those C files and make sense of what’s going on,  
specially when you don’t know C 🙂

I’ve also found some interesting stuff at [http://www.antlr.org/](http://www.antlr.org/), even a  
Ruby command dictionary, very nice. It will be even more interesting  
when I know what to do next 🙂

Thanks a lot, I keep studding.  
Rafael.

---

<div class="post-metadata">

**Author:** ![rafaelrosafu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/59ef9b/32.png) [@rafaelrosafu](https://www.ruby-forum.com/u/rafaelrosafu)\
**Post date:** [December 14, 2008, 1:11am UTC](https://www.ruby-forum.com/t/beggining-the-compiler-journey/155567/4 "2008-12-14T01:11:44Z")

</div>

Rafael R. [2008-12-14 00:42]:

> Thanks for the link, I’ve read the Preface and the took a peek on  
> the index and it seems to be very very close to what I’m looking  
> for, thanks a lot.  
> great.

> As for the readme, I did read it, but it didn’t explain how to  
> understand how the compiler code is organized, and I didn’t  
> expect it to do so 🙂 Without understanding how things should be  
> arranged is very hard to look at all those C files and make sense  
> of what’s going on,  
> yeah, sure. but i had the impression that it provides some places to  
> start with among the many files there are. btw, do you know the Ruby  
> Hacking Guide?

[http://rhg.rubyforge.org/](http://rhg.rubyforge.org/)

and the Integrated Ruby Hacker’s Guide

[http://www.hawthorne-press.com/WebPage\_RHG.html](http://www.hawthorne-press.com/WebPage_RHG.html)

> specially when you don’t know C 🙂  
> i can feel that 😉

> I’ve also found some interesting stuff at [http://www.antlr.org/](http://www.antlr.org/),  
> even a Ruby command dictionary, very nice. It will be even more  
> interesting when I know what to do next 🙂  
> unfortunately, i’m probably not the right person to help you there,  
> sorry. but i’m interested in whatever more experienced people might  
> have to tell you about it.

cheers  
jens

---

<div class="post-metadata">

**Author:** ![rafaelrosafu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/59ef9b/32.png) [@rafaelrosafu](https://www.ruby-forum.com/u/rafaelrosafu)\
**Post date:** [December 14, 2008, 7:16am UTC](https://www.ruby-forum.com/t/beggining-the-compiler-journey/155567/5 "2008-12-14T07:16:27Z")

</div>

On Sat, Dec 13, 2008 at 9:28 PM, Rafael R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Now I wish to take a dive and learn this stuff, but I’m having a hard  
> time finding a good global guide. I’m looking for a book, a tutorial, or  
> anything like that, that can explain the differences between the  
> architecture for a language used with a VM and another without, what’s  
> the impact of these choices when building a compiler, how low level  
> memory management works, what’s the current trend, etc.

Take a look at  
[http://www.hokstad.com/writing-a-compiler-in-ruby-bottom-up-step-1.html](http://www.hokstad.com/writing-a-compiler-in-ruby-bottom-up-step-1.html)

martin

---

<div class="post-metadata">

**Author:** ![rafaelrosafu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/59ef9b/32.png) [@rafaelrosafu](https://www.ruby-forum.com/u/rafaelrosafu)\
**Post date:** [December 14, 2008, 10:02pm UTC](https://www.ruby-forum.com/t/beggining-the-compiler-journey/155567/6 "2008-12-14T22:02:30Z")

</div>

Rafael R. wrote:

> 

Topher Cyil’s book, “Practical Ruby Projects”, has a chapter on parsing  
in Ruby.

You may wish to consider implementing a simple interpreter before a  
compiler. This would let you see something happening sooner. The parsing  
part could be common to both. Some compilers for some languages rely  
heavily on an interpreter disguised as a run-time library.

Have fun,  
Bill

---

<div class="post-metadata">

**Author:** ![rafaelrosafu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/59ef9b/32.png) [@rafaelrosafu](https://www.ruby-forum.com/u/rafaelrosafu)\
**Post date:** [December 14, 2008, 2:16pm UTC](https://www.ruby-forum.com/t/beggining-the-compiler-journey/155567/7 "2008-12-14T14:16:13Z")

</div>

Jen and Martin,

Thanks to both of you, these links are very useful indeed. I’ll dig into  
them as soon as finish a paper I’m working on. The compiler building is  
very very interesting, and it’s seems to be quite accessible too. If  
everything goes as I expect I’ll publish my learning notes somewhere,  
and I’ll let you know.

Thanks a lot,  
Rafael.

---

<div class="post-metadata">

**Author:** ![rafaelrosafu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/59ef9b/32.png) [@rafaelrosafu](https://www.ruby-forum.com/u/rafaelrosafu)\
**Post date:** [December 15, 2008, 11:50pm UTC](https://www.ruby-forum.com/t/beggining-the-compiler-journey/155567/8 "2008-12-15T23:50:23Z")

</div>

On Dec 14, 2008, at 12:47 , William R. wrote:

> You may wish to consider implementing a simple interpreter before a  
> compiler. This would let you see something happening sooner. The  
> parsing part could be common to both. Some compilers for some  
> languages rely heavily on an interpreter disguised as a run-time  
> library.

agreed.

and I’d also recommend sticking to wirth’s book. It is very very  
terse, but a great book. Start with parsing, add an interpreter, and  
move to compiling as your final step.

The ruby compiler link in this thread is interesting in that it starts  
from the bottom and works its way up. That might help or hinder  
depending on your learning style.

Last thing, I’d stick to doing the simplest compiler you can for your  
first one, and not worry about a lot of the issues you brought up in  
your original email. Books like Hennessy & Patterson’s Computer  
Architecture book and some of the newer texts on VM design will cover  
those edge cases very well.
