www.angelfire.com/dragon/letstry
cwave04 at yahoo dot com

Compiler tutorial

This is the second part of the compiler tutorial. It has 7 pages so far. (If you are looking for the first part then you may click here.)

We have grouped the 7 pages into 3 groups. The groups are independent of each other, and may be read in any order.
Two more techniques to write a grammar The elementary tutorial talked about designing your own language, and taught techniques for that. In the first two pages we extend our list of techniques to include a couple of new tricks.
Page 1
Using "useless" rules
Page 2
Understanding how information flows during parsing
Debugging a grammar When designing one's own language one often encounters a particular error message called a shift/reduce conflict. The error is generated by bison (or yacc) when you feed your grammar to it. It will still produce a compiler all right, but the compiler will often behave in a strange way.

The pages below will tell you how to handle shift-reduce conflicts. This involves three things: understaning the working principle of bison, learning how to make bison identify the reason behind the conflict, and finally, how to change your grammar file to avoid the conflict.
Page 3
Using bison to generate a diagnostic file
Page 4
Understanding shift-reduce conflicts
Page 5
Correcting shift-reduce conflicts
Page 6
Some useful theory
Alternatives If you find the job of creating a grammar file too tedious then here are some quick-n-dirty ways out.
Page 7
A few alternatives to writing a grammar.

What you already need to know

This tutorial assumes that you have already completed our elementary tutorial on compilers.

Next
© Arnab Chakraborty (2007)