www.angelfire.com/dragon/letstry
cwave04 at yahoo dot com
Free Guestbook
My Guestbook

Compiler tutorial

The second part of this tutorial is given here.
Page 1
Motivation behind why one should care to design a new language.
Page 2
Introduction to a detailed example that we shall use in the following pages.
Page 3
The parts of a compiler.
Page 4
Lexical analysis for our example
Page 5
Syntax analysis for our example
Page 6
How to write a grammar (basic techniques)
Page 7
Some theory of syntax analysis
Page 8
More on syntax analysis (interactive page, uses javascript)
Page 10
Semantic analysis
Page 11
More on semantic analysis
Page 12
And still more on semantic analysis (interactive page, uses javascript)

What you already need to know

This tutorial assumes that you have basic familiarity with C. For instance, you should know arrays and structure in C. Also, we have used a big example that involves some html and javascript. A basic familiarity with these languages would help you follow the tutorial better.

Other sources

Compiler construction is by no means a lost art, and there are very many excellent sources that one can learn it from. Two very good sources are:
  • The book Compiler Design by Aho, Sethi and Ulman.: It is the classic textbook of the subject, and it is an excellent textbook. But unfortunately it is only a textbook, and lacks lively examples.
  • The Modern Compiler Implementation book (or rather, books, for there are 3 pairs of them, one pair each for Java, C and ML) by Andrew Appel: These books are real gems, and provide a very well balanced treatment in terms of theory and practice. They are full of examples. There is web support available at the author's homepage.

What's special about this tutorial?

Most (if not all) of the good sources of compiler design info (including the two books mentioned above) suffer from two problems. They somehow always focus themselves on how to make a language like C (with possibly a bit of object orientedness thrown in for good measure). But this should by no means be the main aim of a compiler designer. Even if you know how to make new C like languages within a matter of seconds, you should refrain from designing one, because if everyone starts designing his/her personal general purpose language it would defeat the very purpose of having a general purpose language. It is for designing special purpose languages that one should devote one's knowledge. And that's where the fun is mainly! The standard texts (and even some of the standard compiler courses) are strangely silent about this aspect! This tutorial, on the other hand, brings this issue to the fore.

The second shortcoming of the standard texts seems to be their reluctance in teaching how to design a language. They talk a lot about designing the compiler for a language assuming the language syntax is already provided. But in real world, you will rarely start with a ready-made language. You will start with a vague idea about what the language should do and how. This tutorial tries to provide insight into how you turn this vague specification into a set of rigid grammar rules.

Next
© Arnab Chakraborty (2007)

free html visitor counters
hit counter