]> git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
the opening paren is now an operator - to fix up the precedence rules, now 'anentity...
authorWolfgang (Blub) Bumiller <blub@speed.at>
Sat, 18 Aug 2012 13:25:45 +0000 (15:25 +0200)
committerWolfgang (Blub) Bumiller <blub@speed.at>
Sat, 18 Aug 2012 13:25:45 +0000 (15:25 +0200)
data/fields.qc
lexer.h
parser.c

index 19d9cc7968fa697088b3a730ce4e53d6a3d4c361..82b19ec20a13d1705900b232b46e6f3456995d8c 100644 (file)
@@ -44,5 +44,5 @@ void() main = {
 
     pawn.fun = funny;
 
-    (pawn.fun)();
+    pawn.fun();
 };
diff --git a/lexer.h b/lexer.h
index 5bd15f65a1e3fd0cddc64a8da394055fe960761d..5e0d18cd40ffc29e61b2d3e8be89f4939d58a683 100644 (file)
--- a/lexer.h
+++ b/lexer.h
@@ -138,11 +138,13 @@ typedef struct {
 #define opid3(a,b,c) ((a<<16)|(b<<8)|c)
 
 static const oper_info operators[] = {
+    { "(",   0, opid1('('),         ASSOC_LEFT,  99, OP_PREFIX}, /* paren expression - non function call */
+
     { "++",  1, opid3('S','+','+'), ASSOC_LEFT,  16, OP_SUFFIX},
     { "--",  1, opid3('S','-','-'), ASSOC_LEFT,  16, OP_SUFFIX},
 
     { ".",   2, opid1('.'),         ASSOC_LEFT,  15, 0 },
-    { "(",   0, opid1('('),         ASSOC_LEFT,  15, OP_SUFFIX },
+    { "(",   0, opid1('('),         ASSOC_LEFT,  15, 0 }, /* function call */
 
     { "!",   1, opid2('!', 'P'),    ASSOC_RIGHT, 14, OP_PREFIX },
     { "~",   1, opid2('~', 'P'),    ASSOC_RIGHT, 14, OP_PREFIX },
index 769f0da988fc761a75e2f953f94af99146e7809d..1530d39bd25c1f2bc926294d02670a7f7539a83c 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -1110,23 +1110,8 @@ static ast_expression* parser_expression_leave(parser_t *parser, bool stopatcomm
                                 parser_token(parser)->constval.v.z));
         }
         else if (parser->tok == '(') {
-            if (wantop) {
-                DEBUGSHUNTDO(printf("push (\n"));
-                ++parens;
-                /* we expected an operator, this is the function-call operator */
-                if (!shunt_ops_add(&sy, syparen(parser_ctx(parser), 'f', sy.out_count-1))) {
-                    parseerror(parser, "out of memory");
-                    goto onerr;
-                }
-            } else {
-                ++parens;
-                if (!shunt_ops_add(&sy, syparen(parser_ctx(parser), 1, 0))) {
-                    parseerror(parser, "out of memory");
-                    goto onerr;
-                }
-                DEBUGSHUNTDO(printf("push (\n"));
-            }
-            wantop = false;
+            parseerror(parser, "internal error: '(' should be classified as operator");
+            goto onerr;
         }
         else if (parser->tok == ')') {
             if (wantop) {
@@ -1171,7 +1156,6 @@ static ast_expression* parser_expression_leave(parser_t *parser, bool stopatcomm
                     break;
                 }
             }
-            wantop = false;
             if (o == operator_count) {
                 /* no operator found... must be the end of the statement */
                 break;
@@ -1216,9 +1200,30 @@ static ast_expression* parser_expression_leave(parser_t *parser, bool stopatcomm
                     olast = NULL;
             }
 
-            DEBUGSHUNTDO(printf("push operator %s\n", op->op));
-            if (!shunt_ops_add(&sy, syop(parser_ctx(parser), op)))
-                goto onerr;
+            if (op->id == opid1('(')) {
+                if (wantop) {
+                    DEBUGSHUNTDO(printf("push (\n"));
+                    ++parens;
+                    /* we expected an operator, this is the function-call operator */
+                    if (!shunt_ops_add(&sy, syparen(parser_ctx(parser), 'f', sy.out_count-1))) {
+                        parseerror(parser, "out of memory");
+                        goto onerr;
+                    }
+                } else {
+                    ++parens;
+                    if (!shunt_ops_add(&sy, syparen(parser_ctx(parser), 1, 0))) {
+                        parseerror(parser, "out of memory");
+                        goto onerr;
+                    }
+                    DEBUGSHUNTDO(printf("push (\n"));
+                }
+                wantop = false;
+            } else {
+                DEBUGSHUNTDO(printf("push operator %s\n", op->op));
+                if (!shunt_ops_add(&sy, syop(parser_ctx(parser), op)))
+                    goto onerr;
+                wantop = false;
+            }
         }
         if (!parser_next(parser)) {
             goto onerr;