Output Generation

Emitting the code is the simplest of all the phases. Since Parrot requires all the variables to be declared, a comma separated string $dec is built concatenating the keys of the symbol table hash %s. The code is then indented and the different components are articulated through a HERE document:
sub output_code {
  my ($trans, $dec) = @_;

  # Indent
  $$trans =~ s/^/\t/gm;

  # Output the code
print << "TRANSLATION";
.sub 'main' :main
\t.local num $$dec
$$trans
.end
TRANSLATION
The call to output_code finishes the job:
output_code(\$t->{trans}, \$dec);



Procesadores de Lenguaje 2007-03-01