diff options
| author | Mel <einebeere@gmail.com> | 2022-06-20 00:34:31 +0200 |
|---|---|---|
| committer | Mel <einebeere@gmail.com> | 2022-06-20 00:34:31 +0200 |
| commit | 9a847f9ec4a0030bf2194005bc9a79cd609cd48a (patch) | |
| tree | 2c431b2d8691cbe9b6b05691312b6a5b452b624b /pkg/lang/ast/op.go | |
| parent | 1cb973f84473f5c1f65132b39a21e991093cc868 (diff) | |
| download | jinx-9a847f9ec4a0030bf2194005bc9a79cd609cd48a.tar.zst jinx-9a847f9ec4a0030bf2194005bc9a79cd609cd48a.zip | |
Fix messed up BinOp precedence table
Diffstat (limited to 'pkg/lang/ast/op.go')
| -rw-r--r-- | pkg/lang/ast/op.go | 9 |
1 files changed, 5 insertions, 4 deletions
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)) } |
