summaryrefslogtreecommitdiff
path: root/parser/expr.go
diff options
context:
space:
mode:
Diffstat (limited to 'parser/expr.go')
-rw-r--r--parser/expr.go15
1 files changed, 13 insertions, 2 deletions
diff --git a/parser/expr.go b/parser/expr.go
index fa8afa4..207f38b 100644
--- a/parser/expr.go
+++ b/parser/expr.go
@@ -42,10 +42,21 @@ func (p *Parser) ParseExpr(in Tokens) (out Tokens, err error) {
case lang.Int, lang.String:
out = append(out, t)
vl++
- case lang.Define, lang.Add, lang.Sub, lang.Assign, lang.Equal, lang.Greater, lang.Less, lang.Mul, lang.Land, lang.Lor, lang.Shl, lang.Shr:
+ case lang.Define, lang.Add, lang.Sub, lang.Assign, lang.Equal, lang.Greater, lang.Less, lang.Mul, lang.Land, lang.Lor, lang.Shl, lang.Shr, lang.Not:
+ if i == 0 || in[i-1].Id.IsOperator() {
+ // An operator preceded by an operator or no token is unary.
+ t.Id = lang.UnaryOp[t.Id]
+ j := len(out) - 1
+ l := out[j]
+ if p.precedence(l) > 0 {
+ out = append(out[:j], t, l)
+ break
+ }
+ out = append(out, t)
+ break
+ }
if vl < 2 {
ops = append(ops, t)
- break
}
case lang.ParenBlock:
// If the previous token is an arithmetic, logic or assign operator then