diff options
| author | gingerBill <bill@gingerbill.org> | 2021-05-15 19:13:34 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2021-05-15 19:13:34 +0100 |
| commit | 5e31c04a01e5fa1d11c5a72b684263005451980a (patch) | |
| tree | 62ec53e3185f6f3e3b4b732c5f9553d3ce4043dc /src/parser.cpp | |
| parent | 7b7081d60733caa996a89be2651482a2aeed8bbd (diff) | |
Disallow duplicate unary operators for `+`, `-`, and `~`
Diffstat (limited to 'src/parser.cpp')
| -rw-r--r-- | src/parser.cpp | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/src/parser.cpp b/src/parser.cpp index b24bb8aed..f11735af6 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -2754,13 +2754,23 @@ Ast *parse_unary_expr(AstFile *f, bool lhs) { return ast_auto_cast(f, token, expr); } + case Token_And: + case Token_Not: { + Token token = advance_token(f); + Ast *expr = parse_unary_expr(f, lhs); + return ast_unary_expr(f, token, expr); + } + case Token_Add: case Token_Sub: - case Token_Not: - case Token_Xor: - case Token_And: { + case Token_Xor: { Token token = advance_token(f); Ast *expr = parse_unary_expr(f, lhs); + if (expr != nullptr && expr->kind == Ast_UnaryExpr) { + if (expr->UnaryExpr.op.kind == token.kind) { + syntax_error(expr, "Duplicate unary operator '%.*s' will produce a redundant no-op", LIT(token.string)); + } + } return ast_unary_expr(f, token, expr); } |