Skip to content
This repository has been archived by the owner on Feb 3, 2021. It is now read-only.

Commit

Permalink
OPP first step -- parse a term.
Browse files Browse the repository at this point in the history
  • Loading branch information
pmichaud committed Oct 19, 2009
1 parent b596526 commit 5648720
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 6 deletions.
6 changes: 6 additions & 0 deletions src/HLL/Actions.pm
@@ -1,5 +1,11 @@
class HLL::Actions;

method termish($/) {
make $<noun>.ast;
}

method noun:sym<term>($/) { make $<term>.ast }

method integer($/) {
make $<decint>
?? string_to_int( $<decint>, 10)
Expand Down
7 changes: 7 additions & 0 deletions src/HLL/Grammar.pm
@@ -1,5 +1,12 @@
grammar HLL::Grammar;

token termish {
<noun>
}

proto token noun { <...> }
token noun:sym<term> { <term> }

token quote_delimited {
<starter> <quote_atom>* <stopper>
}
Expand Down
13 changes: 8 additions & 5 deletions src/NQP/Actions.pm
@@ -1,13 +1,16 @@
class NQP::Actions is HLL::Actions;

#method TOP($/) {
# make $<value>.ast;
#}
method TOP($/) { make $<EXPR>.ast; }

method term:sym<value>($/) { make $<value>.ast; }

method value($/) {
my $past := PAST::Val.new(
:value($<integer> ?? $<integer>.ast !! $<quote_delimited>.ast)
);
:value($<integer>
?? $<integer>.ast
!! $<quote_delimited>.ast
)
);
make $past;
}

5 changes: 4 additions & 1 deletion src/NQP/Grammar.pm
@@ -1,6 +1,9 @@
grammar NQP::Grammar is HLL::Grammar;

token TOP { <quote> }
token TOP { <EXPR> }

proto token term { <...> }
token term:sym<value> { <value> }

token value {
| <integer>
Expand Down
21 changes: 21 additions & 0 deletions src/cheats/hll-grammar.pir
Expand Up @@ -348,6 +348,27 @@ position C<pos>.
.end


=item EXPR(...)

An operator precedence parser.

=cut

.sub 'EXPR' :method
.local string termish
termish = 'termish'

.local pmc here, term
.local int pos
(here, pos) = self.'!cursor_start'()

here = here.termish()
unless here goto fail

fail:
.return (here)
.end

=cut

# Local Variables:
Expand Down

0 comments on commit 5648720

Please sign in to comment.