From 9a847f9ec4a0030bf2194005bc9a79cd609cd48a Mon Sep 17 00:00:00 2001 From: Mel Date: Mon, 20 Jun 2022 00:34:31 +0200 Subject: Fix messed up BinOp precedence table --- pkg/lang/ast/op.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'pkg/lang/ast/op.go') diff --git a/pkg/lang/ast/op.go b/pkg/lang/ast/op.go index f5fce51..6f48e0c 100644 --- a/pkg/lang/ast/op.go +++ b/pkg/lang/ast/op.go @@ -59,14 +59,15 @@ func BinOpFromToken(tok token.Token) (BinOp, bool) { func (op BinOp) Precedence() int { switch op { - case BinOpPlus, BinOpMinus: + case BinOpAssign: return 1 - case BinOpStar, BinOpSlash, BinOpPercent: + case BinOpEq, BinOpNeq, BinOpLt, BinOpLte, BinOpGt, BinOpGte: return 2 - case BinOpAssign: + case BinOpPlus, BinOpMinus: return 3 - case BinOpEq, BinOpNeq, BinOpLt, BinOpLte, BinOpGt, BinOpGte: + case BinOpStar, BinOpSlash, BinOpPercent: return 4 + default: panic(fmt.Sprintf("unknown binary operator: %d", op)) } -- cgit 1.4.1