examples/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 $parser = Infix->new(); # Set input $parser->YYData->{INPUT} = slurp_file($filename, 'inf'); # Lexical and syntax analysis my $t = $parser->YYParse( yylex => \&Infix::Lex, yyerror => \&Infix::Err); # Tree transformations $t->s(our @algebra); # Address assignment our $reg_assign; $reg_assign->s($t); # Code generation $t->bud(our @translation); 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 4)
using the command:
$ eyapp Infix.eyp $ ls -tr | tail -1 Infix.pmIt also uses the module containing different families of tree transformations that are described in the
I2PIR.trg
file
(explained in
sections 5 and 7):
$ 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 transformations inside the main
namespace.