Created
February 16, 2011 05:37
-
-
Save HashNuke/828925 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The PCT tutorial episode-3 instructs to add this to Actions.pm | |
method term:sym<integer_constant>($/) { | |
make PAST::Val.new(:value($<integer>.ast), :returns<Integer>); | |
} | |
method term:sym<string_constant>($/) { | |
my $past := $<quote>.ast; | |
$past.returns('String'); | |
make $past; | |
} | |
method term:sym<primary>($/) { | |
make $<primary>.ast; | |
} | |
==================================================================== | |
And this is the state of the file after addition: | |
==================================================================== | |
class Squaak::Actions is HLL::Actions; | |
method TOP($/) { | |
make PAST::Block.new( $<statementlist>.ast , :hll<squaak>, :node($/) ); | |
} | |
method statementlist($/) { | |
my $past := PAST::Stmts.new( :node($/) ); | |
for $<statement> { $past.push( $_.ast ); } | |
make $past; | |
} | |
method statement($/) { | |
make $<statement_control> ?? $<statement_control>.ast !! $<EXPR>.ast; | |
} | |
method statement_control:sym<say>($/) { | |
my $past := PAST::Op.new( :name<say>, :pasttype<call>, :node($/) ); | |
for $<EXPR> { $past.push( $_.ast ); } | |
make $past; | |
} | |
method statement_control:sym<print>($/) { | |
my $past := PAST::Op.new( :name<print>, :pasttype<call>, :node($/) ); | |
for $<EXPR> { $past.push( $_.ast ); } | |
make $past; | |
} | |
method term:sym<integer>($/) { make $<integer>.ast; } | |
method term:sym<quote>($/) { make $<quote>.ast; } | |
method quote:sym<'>($/) { make $<quote_EXPR>.ast; } | |
method quote:sym<">($/) { make $<quote_EXPR>.ast; } | |
method circumfix:sym<( )>($/) { make $<EXPR>.ast; } | |
method term:sym<integer_constant>($/) { | |
make PAST::Val.new(:value($<integer>.ast), :returns<Integer>); | |
} | |
method term:sym<string_constant>($/) { | |
my $past := $<quote>.ast; | |
$past.returns('String'); | |
make $past; | |
} | |
method term:sym<primary>($/) { | |
make $<primary>.ast; | |
} | |
==================================================================== | |
Later on in the exercises it says: | |
"Rename the names of the action methods according to the name changes we made on the grammar rules. So, "integer" becomes "integer_constant", and so on." | |
That makes it two methods of the same name method term:sym<integer_constant> and method term:sym<integer_constant> again. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment