The Phases of a Translator

The code below (file infix2pir.pl) displays the stages of the translator: Lexical and syntax analysis, tree transformations and decorations, address assignments, code generation and peephole optimization. The simplicity of the considered language (no types, no control structures) permits the skipping of context handling (also called semantic analysis). Context handling includes jobs like type checking, live analysis, etc. Don't get overflowed for so much terminology: The incoming sections will explain in more detail each of these phases.
my $filename = shift;
my $parser = Infix->new(); 

# read input
$parser->slurp_file($filename);

# lexical and syntax analysis
my $t = $parser->YYParse();

# tree transformations:
# machine independent optimizations
$t->s(our @algebra);  

# Address Assignment 
our $reg_assign;
$reg_assign->s($t);

# Translate to PARROT
$t->bud(our @translation);

# variable declarations
my $dec = build_dec();

peephole_optimization($t->{tr});

output_code(\$t->{tr}, \$dec);

The compiler uses the parser for infix expressions that was generated from the Eyapp grammar Infix.eyp (see section 5) using the command:

$ eyapp Infix.eyp
$ ls -tr | tail -1
Infix.pm
It also uses the module containing different families of tree transformations that are described in the I2PIR.trg file (explained in sections 6 and 8):
$ treereg -m main I2PIR.trg
$ ls -tr | tail -1
I2PIR.pm
$ head -1 I2PIR.pm
package main;
The option -m main tells treereg to place the generated tree transformations inside the main namespace. Is in this file that the variables @algebra, @translation and $reg_assign used during the machine-independent optimization, code generation and register allocation phases are defined.

Procesadores de Lenguajes 2010-01-31