Beggining the compiler journey

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 :slight_smile:

Thanks a lot,
Rafael.

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/

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 :slight_smile:
the README.EXT file might be a good starting point.

cheers
jens

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 :slight_smile: 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 :slight_smile:

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

Thanks a lot, I keep studding.
Rafael.

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 :slight_smile: 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/

and the Integrated Ruby Hacker’s Guide

http://www.hawthorne-press.com/WebPage_RHG.html

specially when you don’t know C :slight_smile:
i can feel that :wink:

I’ve also found some interesting stuff at http://www.antlr.org/,
even a Ruby command dictionary, very nice. It will be even more
interesting when I know what to do next :slight_smile:
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

On Sat, Dec 13, 2008 at 9:28 PM, Rafael R. [email protected]
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

martin

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

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.

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.