]> git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - parser.c
move the member-of check for '.' to after applying the previous dot operators so...
[xonotic/gmqcc.git] / parser.c
index 798f2dd9e606d9b73a56628b787b02e0ac6d6d3f..3608171b31855f8e4dee2aaf4283f3ade7b45a39 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -1167,6 +1167,21 @@ static ast_expression* parser_expression_leave(parser_t *parser, bool stopatcomm
             if (op->id == opid1(',') && !parens && stopatcomma)
                 break;
 
+            if (sy.ops_count && !sy.ops[sy.ops_count-1].paren)
+                olast = &operators[sy.ops[sy.ops_count-1].etype-1];
+
+            while (olast && (
+                    (op->prec < olast->prec) ||
+                    (op->assoc == ASSOC_LEFT && op->prec <= olast->prec) ) )
+            {
+                if (!parser_sy_pop(parser, &sy))
+                    goto onerr;
+                if (sy.ops_count && !sy.ops[sy.ops_count-1].paren)
+                    olast = &operators[sy.ops[sy.ops_count-1].etype-1];
+                else
+                    olast = NULL;
+            }
+
             if (op->id == opid1('.')) {
                 /* for gmqcc standard: open up the namespace of the previous type */
                 ast_expression *prevex = sy.out[sy.out_count-1].out;
@@ -1185,21 +1200,6 @@ static ast_expression* parser_expression_leave(parser_t *parser, bool stopatcomm
                 gotmemberof = true;
             }
 
-            if (sy.ops_count && !sy.ops[sy.ops_count-1].paren)
-                olast = &operators[sy.ops[sy.ops_count-1].etype-1];
-
-            while (olast && (
-                    (op->prec < olast->prec) ||
-                    (op->assoc == ASSOC_LEFT && op->prec <= olast->prec) ) )
-            {
-                if (!parser_sy_pop(parser, &sy))
-                    goto onerr;
-                if (sy.ops_count && !sy.ops[sy.ops_count-1].paren)
-                    olast = &operators[sy.ops[sy.ops_count-1].etype-1];
-                else
-                    olast = NULL;
-            }
-
             if (op->id == opid1('(')) {
                 if (wantop) {
                     DEBUGSHUNTDO(printf("push (\n"));
@@ -1612,14 +1612,15 @@ static bool parser_parse_statement(parser_t *parser, ast_block *block, ast_expre
                     ast_delete(exp);
                     return false;
                 }
-
-                *out = (ast_expression*)ret;
-            } else if (!parser_next(parser)) {
-                parseerror(parser, "expected semicolon");
+            } else {
+                if (!parser_next(parser))
+                    parseerror(parser, "parse error");
                 if (expected->expression.next->expression.vtype != TYPE_VOID) {
                     parseerror(parser, "return without value");
                 }
+                ret = ast_return_new(parser_ctx(parser), NULL);
             }
+            *out = (ast_expression*)ret;
             return true;
         }
         else if (!strcmp(parser_tokval(parser), "if"))
@@ -1692,6 +1693,7 @@ static ast_block* parser_parse_block(parser_t *parser)
             break;
 
         if (!parser_parse_statement(parser, block, &expr)) {
+            parseerror(parser, "parse error");
             ast_block_delete(block);
             block = NULL;
             goto cleanup;
@@ -1723,7 +1725,7 @@ cleanup:
 
 static ast_expression* parser_parse_statement_or_block(parser_t *parser)
 {
-    ast_expression *expr;
+    ast_expression *expr = NULL;
     if (parser->tok == '{')
         return (ast_expression*)parser_parse_block(parser);
     if (!parser_parse_statement(parser, NULL, &expr))