Skip to content
Browse files

Add a termstack, some infix grammar rules.

  • Loading branch information...
1 parent 5648720 commit f4c2dcb3d73fab8643bcd79f1419cd3584ad6a10 @pmichaud pmichaud committed
Showing with 26 additions and 3 deletions.
  1. +4 −0 src/NQP/Grammar.pm
  2. +22 −3 src/cheats/hll-grammar.pir
View
4 src/NQP/Grammar.pm
@@ -5,6 +5,10 @@ token TOP { <EXPR> }
proto token term { <...> }
token term:sym<value> { <value> }
+proto token infix { <...> }
+token infix:sym<+> { '+' }
+token infix:sym<-> { '-' }
+
token value {
| <integer>
| <quote_delimited>
View
25 src/cheats/hll-grammar.pir
@@ -358,15 +358,34 @@ An operator precedence parser.
.local string termish
termish = 'termish'
- .local pmc here, term
- .local int pos
+ .local pmc opstack, termstack
+ opstack = new ['ResizablePMCArray']
+ .lex '@opstack', opstack
+ termstack = new ['ResizablePMCArray']
+ .lex '@termstack', termstack
+
+ .local pmc here, infix, from, pos
(here, pos) = self.'!cursor_start'()
here = here.termish()
unless here goto fail
-
+ push termstack, here
+
+ term_done:
+ # $I0 = elements termstack
+ # if $I0 != 1 goto err_internal
+ from = getattribute self, '$!from'
+ pos = getattribute here, '$!pos'
+ here = pop termstack
+ setattribute here, '$!from', from
+ setattribute here, '$!pos', pos
+ here.'!reduce'('EXPR')
fail:
.return (here)
+
+ err_internal:
+ $I0 = termstack
+ here.'panic'('Internal operator parser error, @termstack == ', $I0)
.end
=cut

0 comments on commit f4c2dcb

Please sign in to comment.
Something went wrong with that request. Please try again.