Skip to content

Commit c84aaf0

Browse files
committed
Another bunch of updates to EXPR. Gets us closer to working OPP with QRegex.
1 parent abb07dc commit c84aaf0

File tree

1 file changed

+32
-13
lines changed

1 file changed

+32
-13
lines changed

src/QHLL/Grammar.pm

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -564,12 +564,14 @@ An operator precedence parser.
564564
.lex '@termstack', termstack
565565
566566
term_loop:
567+
.local pmc termcur
568+
repr_bind_attr_int here, cur_class, "$!pos", pos
569+
termcur = here.termishrx()
570+
pos = repr_get_attr_int termcur, cur_class, "$!pos"
567571
repr_bind_attr_int here, cur_class, "$!pos", pos
568-
here = here.termishrx()
569-
pos = repr_get_attr_int here, cur_class, "$!pos"
570572
if pos < 0 goto fail
571573
.local pmc termish
572-
termish = here.'MATCH'()
574+
termish = termcur.'MATCH'()
573575

574576
# interleave any prefix/postfix we might have found
575577
.local pmc termOPER, prefixish, postfixish
@@ -633,28 +635,39 @@ An operator precedence parser.
633635

634636
# Now see if we can fetch an infix operator
635637
.local pmc wscur, infixcur, infix
638+
639+
# First, we need ws to match.
640+
repr_bind_attr_int here, cur_class, "$!pos", pos
636641
wscur = here.'ws'()
637-
$I0 = repr_get_attr_int wscur, cur_class, '$!pos'
638-
if $I0 < 0 goto term_done
639-
here = wscur
642+
pos = repr_get_attr_int wscur, cur_class, '$!pos'
643+
if pos < 0 goto term_done
644+
repr_bind_attr_int here, cur_class, "$!pos", pos
645+
646+
# Next, try the infix itself.
640647
infixcur = here.'infixish'()
641-
$I0 = repr_get_attr_int here, cur_class, '$!pos'
642-
if $I0 < 0 goto term_done
648+
pos = repr_get_attr_int infixcur, cur_class, '$!pos'
649+
if pos < 0 goto term_done
643650
infix = infixcur.'MATCH'()
644651

652+
# We got an infix.
645653
.local pmc inO
646654
$P0 = infix['OPER']
647655
inO = $P0['O']
648-
termishrx = inO['nextterm']
656+
$P0 = inO['nextterm']
657+
if null $P0 goto nonextterm
658+
termishrx = $P0
649659
if termishrx goto have_termishrx
660+
nonextterm:
650661
termishrx = 'termish'
651662
have_termishrx:
652663

653664
.local string inprec, inassoc, opprec
654-
inprec = inO['prec']
665+
$P0 = inO['prec']
666+
inprec = $P0
655667
unless inprec goto err_inprec
656668
if inprec <= preclim goto term_done
657-
inassoc = inO['assoc']
669+
$P0 = inO['assoc']
670+
inassoc = $P0
658671

659672
$P0 = inO['sub']
660673
if null $P0 goto subprec_done
@@ -666,7 +679,8 @@ An operator precedence parser.
666679
$P0 = opstack[-1]
667680
$P0 = $P0['OPER']
668681
$P0 = $P0['O']
669-
opprec = $P0['prec']
682+
$P0 = $P0['prec']
683+
opprec = $P0
670684
unless opprec > inprec goto reduce_gt_done
671685
self.'EXPR_reduce'(termstack, opstack)
672686
goto reduce_loop
@@ -680,7 +694,11 @@ An operator precedence parser.
680694
reduce_done:
681695

682696
push opstack, infix # The Shift
683-
here = infixcur.'ws'()
697+
repr_bind_attr_int here, cur_class, "$!pos", pos
698+
wscur = here.'ws'()
699+
pos = repr_get_attr_int wscur, cur_class, '$!pos'
700+
repr_bind_attr_int here, cur_class, "$!pos", pos
701+
if pos < 0 goto fail
684702
goto term_loop
685703
term_done:
686704

@@ -695,6 +713,7 @@ An operator precedence parser.
695713
term = pop termstack
696714
pos = here.'pos'()
697715
here = self.'!cursor_start'()
716+
here.'!cursor_pass'(pos)
698717
repr_bind_attr_int here, cur_class, '$!pos', pos
699718
setattribute here, cur_class, '$!match', term
700719
here.'!reduce'('EXPR')

0 commit comments

Comments
 (0)