@@ -564,12 +564,14 @@ An operator precedence parser.
564
564
.lex '@termstack', termstack
565
565
566
566
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"
567
571
repr_bind_attr_int here, cur_class, " $ ! pos" , pos
568
- here = here. termishrx()
569
- pos = repr_get_attr_int here, cur_class, " $ ! pos"
570
572
if pos < 0 goto fail
571
573
. local pmc termish
572
- termish = here . ' MATCH' ()
574
+ termish = termcur . ' MATCH' ()
573
575
574
576
# interleave any prefix/postfix we might have found
575
577
. local pmc termOPER, prefixish, postfixish
@@ -633,28 +635,39 @@ An operator precedence parser.
633
635
634
636
# Now see if we can fetch an infix operator
635
637
. local pmc wscur, infixcur, infix
638
+
639
+ # First, we need ws to match.
640
+ repr_bind_attr_int here, cur_class, " $ ! pos" , pos
636
641
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.
640
647
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
643
650
infix = infixcur. ' MATCH' ()
644
651
652
+ # We got an infix.
645
653
. local pmc inO
646
654
$ P0 = infix [' OPER' ]
647
655
inO = $ P0 [' O' ]
648
- termishrx = inO[' nextterm' ]
656
+ $ P0 = inO[' nextterm' ]
657
+ if null $ P0 goto nonextterm
658
+ termishrx = $ P0
649
659
if termishrx goto have_termishrx
660
+ nonextterm:
650
661
termishrx = ' termish'
651
662
have_termishrx:
652
663
653
664
. local string inprec, inassoc, opprec
654
- inprec = inO[' prec' ]
665
+ $ P0 = inO[' prec' ]
666
+ inprec = $ P0
655
667
unless inprec goto err_inprec
656
668
if inprec <= preclim goto term_done
657
- inassoc = inO[' assoc' ]
669
+ $ P0 = inO[' assoc' ]
670
+ inassoc = $ P0
658
671
659
672
$ P0 = inO[' sub' ]
660
673
if null $ P0 goto subprec_done
@@ -666,7 +679,8 @@ An operator precedence parser.
666
679
$ P0 = opstack[-1 ]
667
680
$ P0 = $ P0 [' OPER' ]
668
681
$ P0 = $ P0 [' O' ]
669
- opprec = $ P0 [' prec' ]
682
+ $ P0 = $ P0 [' prec' ]
683
+ opprec = $ P0
670
684
unless opprec > inprec goto reduce_gt_done
671
685
self . ' EXPR_reduce' (termstack, opstack)
672
686
goto reduce_loop
@@ -680,7 +694,11 @@ An operator precedence parser.
680
694
reduce_done:
681
695
682
696
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
684
702
goto term_loop
685
703
term_done:
686
704
@@ -695,6 +713,7 @@ An operator precedence parser.
695
713
term = pop termstack
696
714
pos = here. ' pos' ()
697
715
here = self . ' !cursor_start' ()
716
+ here. ' !cursor_pass' (pos )
698
717
repr_bind_attr_int here, cur_class, ' $!pos' , pos
699
718
setattribute here, cur_class, ' $!match' , term
700
719
here. ' !reduce' (' EXPR' )
0 commit comments