Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Complain when non-assocs get associated.

  • Loading branch information...
commit 8ea7814afdae442caaf424ae05d7fc37dac830d4 1 parent bcd4f82
@jnthn jnthn authored
Showing with 11 additions and 0 deletions.
  1. +11 −0 src/HLL/Grammar.pm
View
11 src/HLL/Grammar.pm
@@ -638,6 +638,13 @@ An operator precedence parser.
unless opprec == inprec goto reduce_done
# equal precedence, use associativity to decide
inassoc = inO['assoc']
+ unless inassoc == 'non' goto assoc_ok
+ $P0 = opstack[-1]
+ $P0 = $P0['OPER']
+ $P0 = $P0['sym']
+ $P1 = infix.'Str'()
+ self.'EXPR_nonassoc'(infixcur, $P0, $P1)
+ assoc_ok:
unless inassoc == 'left' goto reduce_done
# left associative, reduce immediately
self.'EXPR_reduce'(termstack, opstack)
@@ -766,6 +773,10 @@ An operator precedence parser.
push termstack, op
};
}
+
+ method EXPR_nonassoc($cur, $op1, $op2) {
+ $cur.panic('"' ~ $op1 ~ '" and "' ~ $op2 ~ '" are non-associative and require parens');
+ }
method ternary($match) {
$match[2] := $match[1];
Please sign in to comment.
Something went wrong with that request. Please try again.