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

Commit

Permalink
Allow nextterm specifier, nulltermish tokens.
Browse files Browse the repository at this point in the history
  • Loading branch information
pmichaud committed Oct 20, 2009
1 parent 7591d1c commit 7451fb8
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
4 changes: 4 additions & 0 deletions src/NQP/Actions.pm
Expand Up @@ -9,6 +9,7 @@ NQP::Grammar.O(':prec<u=>, :assoc<left>', '%multiplicative');
NQP::Grammar.O(':prec<t=>, :assoc<left>', '%additive');
NQP::Grammar.O(':prec<r=>, :assoc<list>', '%concatenation');
NQP::Grammar.O(':prec<i=>, :assoc<right>', '%assignment');
NQP::Grammar.O(':prec<g=>, :assoc<list>, :nextterm<nulltermish>', '%comma');

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

Expand All @@ -30,3 +31,6 @@ method value($/) {
make $past;
}

method nulltermish($/) {
make $<noun> ?? $<noun>.ast !! 0;
}
6 changes: 5 additions & 1 deletion src/NQP/Grammar.pm
Expand Up @@ -14,6 +14,7 @@ token infix:sym<+> { $<sym>=['+'] <O('%additive , :pirop<add>')> }
token infix:sym<-> { $<sym>=['-'] <O('%additive , :pirop<sub>')> }
token infix:sym<=> { $<sym>=['='] <O('%assignment')> }
token infix:sym<~> { $<sym>=['~'] <O('%concatenation')> }
token infix:sym<,> { $<sym>=[','] <O('%comma')> }

token prefix:sym<-> { $<sym>=['-'] <O('%symbolic_unary')> }
token prefix:sym<--> { $<sym>=['--'] <O('%autoincrement')> }
Expand All @@ -38,4 +39,7 @@ token quote:sym<" "> { <?["]> <quote_EXPR: ':qq'> }
token quote:sym<q> { 'q' <![(]> <.ws> <quote_EXPR: ':q'> }
token quote:sym<qq> { 'qq' <![(]> <.ws> <quote_EXPR: ':qq'> }


token nulltermish {
| <OPER=noun=noun>
| <?>
}
30 changes: 22 additions & 8 deletions src/cheats/hll-grammar.pir
Expand Up @@ -377,15 +377,22 @@ An operator precedence parser.
term_loop:
here = here.termish()
unless here goto fail
termish = 'termish'
.local pmc term
term = here.'MATCH'()
push termstack, term

# interleave any prefix/postfix we might have found
.local pmc prefixish, postfixish
prefixish = term['prefixish']
postfixish = term['postfixish']
.local pmc termOPER, prefixish, postfixish
termOPER = term
termOPER_loop:
$I0 = exists termOPER['OPER']
unless $I0 goto termOPER_done
termOPER = termOPER['OPER']
goto termOPER_loop
termOPER_done:
prefixish = termOPER['prefixish']
postfixish = termOPER['postfixish']
if null prefixish goto prefix_done

prepostfix_loop:
unless prefixish goto prepostfix_done
Expand Down Expand Up @@ -423,6 +430,7 @@ An operator precedence parser.
delete term['prefixish']

postfix_loop:
if null postfixish goto postfix_done
unless postfixish goto postfix_done
$P0 = pop postfixish
push opstack, $P0
Expand All @@ -437,13 +445,19 @@ An operator precedence parser.
unless infixcur goto term_done
infix = infixcur.'MATCH'()

.local pmc inO
$P0 = infix['OPER']
inO = $P0['O']
termish = inO['nextterm']
if termish goto have_termish
termish = 'termish'
have_termish:

unless opstack goto reduce_done
.local string inprec, inassoc, opprec
$P0 = infix['OPER']
$P0 = $P0['O']
inprec = $P0['prec']
inassoc = $P0['assoc']
inprec = inO['prec']
unless inprec goto err_inprec
inassoc = inO['assoc']

reduce_loop:
unless opstack goto reduce_done
Expand Down

0 comments on commit 7451fb8

Please sign in to comment.