Skip to content

Instantly share code, notes, and snippets.

@cognominal
Created April 9, 2012 14:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cognominal/2343861 to your computer and use it in GitHub Desktop.
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
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);
}
}
@cognominal
Copy link
Author

any statement, (like "1;") in place of the commented ones , triggers the error message : Unable to parse blockoid, couldn't find final '}'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment