aboutsummaryrefslogtreecommitdiff
path: root/src/parser.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2021-05-15 19:34:46 +0100
committergingerBill <bill@gingerbill.org>2021-05-15 19:34:46 +0100
commit5d03bc61b870d525536290627044e9638c3495b9 (patch)
tree77c74045e3c6a0c8b2f51ba74526577d10aa8cec /src/parser.cpp
parent5e31c04a01e5fa1d11c5a72b684263005451980a (diff)
Tokenize `++` and `--` as tokens but disallow them in the parser, and give better error messages for they are used as operators/statements
Diffstat (limited to 'src/parser.cpp')
-rw-r--r--src/parser.cpp33
1 files changed, 25 insertions, 8 deletions
diff --git a/src/parser.cpp b/src/parser.cpp
index f11735af6..0dae732e5 100644
--- a/src/parser.cpp
+++ b/src/parser.cpp
@@ -2724,6 +2724,16 @@ Ast *parse_atom_expr(AstFile *f, Ast *operand, bool lhs) {
}
break;
+ case Token_Increment:
+ case Token_Decrement:
+ if (!lhs) {
+ Token token = advance_token(f);
+ syntax_error(token, "Postfix '%.*s' operator is not supported", LIT(token.string));
+ } else {
+ loop = false;
+ }
+ break;
+
default:
loop = false;
break;
@@ -2754,6 +2764,10 @@ Ast *parse_unary_expr(AstFile *f, bool lhs) {
return ast_auto_cast(f, token, expr);
}
+
+ case Token_Add:
+ case Token_Sub:
+ case Token_Xor:
case Token_And:
case Token_Not: {
Token token = advance_token(f);
@@ -2761,19 +2775,15 @@ Ast *parse_unary_expr(AstFile *f, bool lhs) {
return ast_unary_expr(f, token, expr);
}
- case Token_Add:
- case Token_Sub:
- case Token_Xor: {
+ case Token_Increment:
+ case Token_Decrement: {
Token token = advance_token(f);
+ syntax_error(token, "Unary '%.*s' operator is not supported", LIT(token.string));
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);
}
+
case Token_Period: {
Token token = expect_token(f, Token_Period);
Ast *ident = parse_ident(f);
@@ -3163,6 +3173,13 @@ Ast *parse_simple_stmt(AstFile *f, u32 flags) {
return ast_bad_stmt(f, token, f->curr_token);
}
+ switch (token.kind) {
+ case Token_Increment:
+ case Token_Decrement:
+ advance_token(f);
+ syntax_error(token, "Postfix '%.*s' statement is not supported", LIT(token.string));
+ break;
+ }
#if 0