Skip to content

Commit

Permalink
Complain when non-assocs get associated.
Browse files Browse the repository at this point in the history
  • Loading branch information
jnthn committed Dec 29, 2012
1 parent bcd4f82 commit 8ea7814
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/HLL/Grammar.pm
Expand Up @@ -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)
Expand Down Expand Up @@ -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];
Expand Down

0 comments on commit 8ea7814

Please sign in to comment.