Created
April 9, 2012 14:33
-
-
Save cognominal/2343861 to your computer and use it in GitHub Desktop.
using qbootstrap, trying to rewrite EXPR_reduce in pure nqp, the commented instructions trip nqp #nqp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class A { | |
# @opd is the operand stack; @opr is the operator stack | |
method EXPR_reduce(@opd, @opr) { | |
my $opr := @opr.pop(); | |
my %opOPER := $opr<OPER>; | |
my %opO := %opOPER<O>; # property hash of the operator | |
my $opAssoc := %opO<assoc>; | |
my $what; | |
if $opAssoc eq 'unary' { | |
my $arg := @opd.pop(); | |
$opr[0] := $arg; | |
# $what := $arg.from() < $opr.from() ?? 'POSTFIX' !! 'PREFIX'; | |
} elsif $opAssoc eq 'list' { | |
my $sym := opOPER['sym'] // ''; | |
$opr.unshift(@opd.pop()); | |
while @opr { | |
my $s := @opr[@opr-1]<OPER><sym> // ''; | |
last if $sym eq $s; | |
$opr.unshift(@opd.pop()); | |
@opr.pop(); | |
} | |
$opr.unshift(@opd.pop()); | |
$what := 'LIST'; | |
} else { | |
$opr[0] := @opd.pop(); | |
$opr[1] := @opd.pop(); | |
my $r := %opO<reducecheck>; | |
if $r { | |
my $s := ~$r; | |
self."$s"($opr); | |
} | |
$what := 'INFIX'; | |
} | |
# self.reduce_with_match('EXPR', $what, $opr); | |
@opr.push($opr); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
any statement, (like "1;") in place of the commented ones , triggers the error message : Unable to parse blockoid, couldn't find final '}'