Live data from Hacker News

Let’s Build a Compiler (1995)

compilers.iecc.com

51–58 of 58 posts

Re: Let’s Build a Compiler (1995)

#51
Personally this is my favorite work on compiler theory. While dragon book is definitely more comprehensive, Let's Build a Compiler is far more approachable (so approachable that I worked through it when I was only 14).

I haven't gone to the bare metal level since (as well as using parser generators), but it's a great piece of work that gives you a slight understanding of what YACC+family do under the covers (even though they are different types of parsers). I continually recommend it as a starting point for anyone who wants to learn how to write parsers.

Re: Let’s Build a Compiler (1995)

#52
post #4

I went through this on my own back in a HS programming class! Glad to see it here. While the teacher was walking students through how to do loops, I got permission to hack away in the back of the room on this. I ended up building a BASIC-like interpreter with a decent graphics API. By the end of the class, my project was a multi-level breakout game I'd written in the interpreter I'd written. TLDR; two years later, I…

You're lucky, I was doing the same things in middle school. Took me until college for that last part... :) That same game project I started then still has been going on since then, multiple compilers and VMs written to do parts of the game. It's ended up an incredibly complex monstrosity with procedurally generated worlds and randomly altered scripts (some actions just won't be available on some play-throughs).

Is the game (or its code) online somewhere? :P

Re: Let’s Build a Compiler (1995)

#53

I followed this in the early 90s and had a lovely time. It helped that Turbo Pascal was my language of choice though and might not be quite so helpful now although Pascal is a pretty good pseudocode.. It's not the same but Vidar Hokstad has been writing a series for several years now in Ruby: http://www.hokstad.com/compiler/ .. and other resources aplenty: http://stackoverflow.com/a/1672/3951

Thanks for the mention... I'll be pushing out the next part in a couple of days. And I'm just wrapping up a part on register allocation.

The really great part with the Crenshaw tutorial, is that it's so cohesive and concise. It's reminiscent of Wirths compiler construction texts, but much simpler to follow.

Re: Let’s Build a Compiler (1995)

#54
post #43

I followed this in the early 90s and had a lovely time. It helped that Turbo Pascal was my language of choice though and might not be quite so helpful now although Pascal is a pretty good pseudocode.. It's not the same but Vidar Hokstad has been writing a series for several years now in Ruby: http://www.hokstad.com/compiler/ .. and other resources aplenty: http://stackoverflow.com/a/1672/3951

> Pascal is a pretty good pseudocode.. Pascal is pretty much directly derived from early dialects of Algol, which is where most modern programming language syntaxes derive; it's the original block-structured syntax, as opposed to line-structured assembly and early FORTRAN and the fully-bracketed Lisp syntax (which is also block-structured if you indent it sanely).

And the reason Pascal is pretty much directly derived from Algol is that Wirth was on the Algol committee, and kept trying to get it simplified and tightened up. He then eventually went on to do Euler and Pascal (and of course later Modula and Oberon) to implement the ideas he'd had for Algol.

This is quite interesting: Pascal and its Successors - Niklaus Wirth http://www.swissdelphicenter.ch/en/niklauswirth.php

Re: Let’s Build a Compiler (1995)

#55

Reading the text files, using vim, which were written in the 80s and talk about Borland and other old stuff, makes me... a bit sentimental.

Talking about sentimental, This made me giggle, "there will probably never come a time when a good assembler-language programmer can't out-program a compiler." Reading that reminded me why I'll never make predictions on computing, especially on what can't be done.

A good assembler-language programmer these days starts with the output of a compiler. And then proceeds to beat the pants off said compiler by optimizing specific portions.

Not least because no language includes sufficient semantic information for the compiler to be able to safely optimize all the parts that the programmer can.

It's still mostly true - just not worth the effort for anything but smaller fragments.

Re: Let’s Build a Compiler (1995)

#56
post #55

Earlier quoted context omitted.

Talking about sentimental, This made me giggle, "there will probably never come a time when a good assembler-language programmer can't out-program a compiler." Reading that reminded me why I'll never make predictions on computing, especially on what can't be done.

A good assembler-language programmer these days starts with the output of a compiler. And then proceeds to beat the pants off said compiler by optimizing specific portions. Not least because no language includes sufficient semantic information for the compiler to be able to safely optimize all the parts that the programmer can . It's still mostly true - just not worth the effort for anything but smaller fragments.

Yeah, I was going to say something similar. You'll never get a compiler to be as intelligent as a human being. At best you'll get human intelligence rapidly applied by a computer to a problem. The computer will be able to do this "manual labor" (if you want to call it that) faster than a human can. However, a human being will be able to find ways to optimize for the problem that a computer will not be able to.

I realize that many people believe that computers will some day be able to truly think on a human level. I just don't happen to be one of those people.

Re: Let’s Build a Compiler (1995)

#57

Earlier quoted context omitted.

A port of it to Python would probably be a better place to start. Not many people are conversant in Pascal these days.

It gives me an excuse to install Free Pascal and give it a whirl though.

That's the spirit!

Re: Let’s Build a Compiler (1995)

#58

Earlier quoted context omitted.

You're lucky, I was doing the same things in middle school. Took me until college for that last part... :) That same game project I started then still has been going on since then, multiple compilers and VMs written to do parts of the game. It's ended up an incredibly complex monstrosity with procedurally generated worlds and randomly altered scripts (some actions just won't be available on some play-throughs).

Is the game (or its code) online somewhere? :P

Not yet, there's been many incarnation, but none of them ever reached a playable state. I've been on a kick to restart it lately after starting to learn prolog. I've been playing with some pre-made engines to find out if any of them can accelerate the whole thing a bit. Checking out Unity right now.
Post reply on HN