pl@nereida:~/doc/casiano/PLBOOK/PLBOOK/code/Aho-Polymorphism/lib/Aho/script$ cat -n usepoly.pl 1 #!/usr/bin/perl -I../lib -w 2 use strict; 3 use Aho::Polymorphism; 4 use Aho::Unify qw(:all); 5 use Parse::Eyapp::Base qw{:all}; 6 use Data::Dumper; 7 8 # Read Input 9 my $filename = shift || die "Usage:\n$0 file.c\n"; 10 my $debug = shift; 11 $debug = 0 unless defined($debug); 12 my $input = slurp_file($filename, "ply"); 13 print $input if $debug; 14 15 # Syntax Analysis and Type Inference 16 my $parser = Aho::Polymorphism->new(); 17 my $t = $parser->compile($input); 18 19 # Show decorated tree 20 $Parse::Eyapp::Node::INDENT = $debug; 21 push_method(qw{FUNCTIONCALL ARGS}, info => sub { strunifiedtree($_[0]->{t}) }); 22 push_method(qw{ID}, info => sub { $_[0]->{attr}[0].":".strunifiedtree($_[0]->{t}) }); 23 print "Tree: ".$t->str."\n"; 24 25 # Print Symbol Table 26 my $symboltable = $t->{symboltable}; 27 for (keys(%$symboltable)) { 28 print "$_ type: " 29 . $symboltable->{$_}{ts} 30 ."\n"; 31 }