Not Quite Perl Not Quite Perl - A lightweight Perl 6 #16

Example "compiler", part 1 of 2

# parser
 
 
    rule expr { <integer> <addop> <integer> };
 
 
 

# transform to ast
 
 
 
 
 
    method expr($/) { 
        my $pirop := $<addop> eq '-' ?? 'sub' !! 'add';
        make PAST::Op.new( :pirop($pirop), 
                 +$<integer>[0], +$<integer>[1]);
    }
 
Copyright © 2010
http://www.pmichaud.com/2010/pres/