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

Commit

Permalink
Handle postcircumfix: parsing.
Browse files Browse the repository at this point in the history
  • Loading branch information
pmichaud committed Oct 20, 2009
1 parent b0d3c56 commit 4e5addc
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
6 changes: 5 additions & 1 deletion src/HLL/Grammar.pm
Expand Up @@ -11,13 +11,17 @@ grammar HLL::Grammar;
proto token prefix { <...> }
proto token postfix { <...> }
proto token circumfix { <...> }
proto token postcircumfix { <...> }

token noun:sym<term> { <term> }
token noun:sym<circumfix> { <circumfix> }

token infixish { <OPER=infix=infix> }
token prefixish { <OPER=prefix=prefix> }
token postfixish { <OPER=postfix=postfix> }
token postfixish {
| <OPER=postfix=postfix>
| <OPER=postcircumfix=postcircumfix>
}

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

# These will eventually go in NQP::Grammar.
NQP::Grammar.O(':prec<y=>, :assoc<unary>', '%methodop');
NQP::Grammar.O(':prec<x=>, :assoc<unary>', '%autoincrement');
NQP::Grammar.O(':prec<w=>, :assoc<left>', '%exponentiation');
NQP::Grammar.O(':prec<v=>, :assoc<unary>', '%symbolic_unary');
Expand All @@ -14,6 +15,10 @@ method term:sym<value>($/) { make $<value>.ast; }

method circumfix:sym<( )>($/) { make $<EXPR>.ast; }

method postcircumfix:sym<[ ]>($/) {
make PAST::Op.new( $<EXPR>.ast , :name('postcircumfix:<[ ]>') );
}

method value($/) {
my $past := PAST::Val.new(
:value($<integer>
Expand Down
5 changes: 5 additions & 0 deletions src/NQP/Grammar.pm
Expand Up @@ -21,6 +21,11 @@ token postfix:sym<++> { $<sym>=['++'] <O('%autoincrement')> }

token circumfix:sym<( )> { '(' <EXPR> ')' }

token postcircumfix:sym<[ ]> {
'[' <EXPR> ']'
<O('%methodop')>
}

token value {
| <integer>
| <quote_delimited>
Expand Down
20 changes: 13 additions & 7 deletions src/cheats/hll-grammar.pir
Expand Up @@ -389,20 +389,26 @@ An operator precedence parser.
prepostfix_loop:
unless prefixish goto prepostfix_done
unless postfixish goto prepostfix_done
.local pmc preO, postO
.local string preprec, postprec
$P0 = prefixish[0]
$P0 = $P0['OPER']
preprec = $P0['prec']
preO = $P0['O']
preprec = preO['prec']
$P0 = postfixish[0]
$P0 = $P0['OPER']
postprec = $P0['prec']
if postprec < preprec goto postltpre
postgtpre:
$P0 = shift prefixish
postO = $P0['O']
postprec = postO['prec']
if postprec < preprec goto post_shift
if postprec > preprec goto pre_shift
$S0 = postO['uassoc']
if $S0 == 'right' goto pre_shift
post_shift:
$P0 = shift postfixish
push opstack, $P0
goto prepostfix_loop
postltpre:
$P0 = shift postfixish
pre_shift:
$P0 = shift prefixish
push opstack, $P0
goto prepostfix_loop
prepostfix_done:
Expand Down

0 comments on commit 4e5addc

Please sign in to comment.