Skip to content

Commit

Permalink
Add sub calls to example compiler.
Browse files Browse the repository at this point in the history
  • Loading branch information
tcurtis committed Jul 19, 2010
1 parent 1f22fac commit 18859f4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/Squaak/Actions.pm
Expand Up @@ -89,6 +89,21 @@ method statement:sym<if>($/) {
make $past;
}

method statement:sym<sub_call>($/) {
my $invocant := $<primary>.ast;
my $past := $<arguments>.ast;
$past.unshift($invocant);
make $past;
}

method arguments($/) {
my $past := PAST::Op.new( :pasttype('call'), :node($/) );
for $<expression> {
$past.push($_.ast);
}
make $past;
}

method statement:sym<throw>($/) {
make PAST::Op.new( $<expression>.ast,
:pirop('throw'),
Expand Down
8 changes: 8 additions & 0 deletions src/Squaak/Grammar.pm
Expand Up @@ -61,6 +61,14 @@ rule statement:sym<if> {
'end'
}

rule statement:sym<sub_call> {
<primary> <arguments>
}

rule arguments {
'(' [<expression> ** ',']? ')'
}

rule statement:sym<throw> {
<sym> <expression>
}
Expand Down

0 comments on commit 18859f4

Please sign in to comment.