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

Commit

Permalink
Add a termstack, some infix grammar rules.
Browse files Browse the repository at this point in the history
  • Loading branch information
pmichaud committed Oct 19, 2009
1 parent 5648720 commit f4c2dcb
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/NQP/Grammar.pm
Expand Up @@ -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>
Expand Down
25 changes: 22 additions & 3 deletions src/cheats/hll-grammar.pir
Expand Up @@ -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
Expand Down

0 comments on commit f4c2dcb

Please sign in to comment.