]> git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
array index opening-paren can now return TOKEN_OPERATOR, partially handled in SYA
authorWolfgang (Blub) Bumiller <blub@speed.at>
Sun, 11 Nov 2012 15:43:16 +0000 (16:43 +0100)
committerWolfgang (Blub) Bumiller <blub@speed.at>
Sun, 11 Nov 2012 15:43:16 +0000 (16:43 +0100)
lexer.c
parser.c

diff --git a/lexer.c b/lexer.c
index 9f1fc4e37640c96ef868de8a01c1807fc1ce5f18..e68af816853ad5dc0637e681f5e685831f337d43 100644 (file)
--- a/lexer.c
+++ b/lexer.c
@@ -867,6 +867,8 @@ int lex_do(lex_file *lex)
         case '{':
         case '}':
         case '[':
+            if (!lex->flags.noops)
+                return (lex->tok.ttype = TOKEN_OPERATOR);
         case ']':
 
         case '#':
index 076d9df791ac06467b7ee661f6e50550b1fc1020..12241cb7083aff4b61106ca364445d7ccbda0e6e 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -999,6 +999,10 @@ static bool parser_close_paren(parser_t *parser, shunt *sy, bool functions_only)
             sy->ops_count--;
             return !functions_only;
         }
+        if (sy->ops[sy->ops_count-1].paren == SY_PAREN_INDEX) {
+            sy->ops_count--;
+            return true;
+        }
         if (!parser_sy_pop(parser, sy))
             return false;
     }
@@ -1183,6 +1187,16 @@ static ast_expression* parse_expression_leave(parser_t *parser, bool stopatcomma
             }
             wantop = true;
         }
+        else if (parser->tok == ']') {
+            if (!wantop)
+                parseerror(parser, "operand expected");
+            --parens;
+            if (parens < 0)
+                break;
+            if (!parser_close_paren(parser, &sy, false))
+                goto onerr;
+            wantop = true;
+        }
         else if (parser->tok != TOKEN_OPERATOR) {
             if (wantop) {
                 parseerror(parser, "expected operator or end of statement");
@@ -1270,6 +1284,16 @@ static ast_expression* parse_expression_leave(parser_t *parser, bool stopatcomma
                     DEBUGSHUNTDO(printf("push [nop] (\n"));
                 }
                 wantop = false;
+            } else if (op->id == opid1('[')) {
+                if (!wantop) {
+                    parseerror(parser, "unexpected array subscript");
+                    goto onerr;
+                }
+                ++parens;
+                if (!shunt_ops_add(&sy, syparen(parser_ctx(parser), SY_PAREN_INDEX, 0))) {
+                    parseerror(parser, "out of memory");
+                    goto onerr;
+                }
             } else {
                 DEBUGSHUNTDO(printf("push operator %s\n", op->op));
                 if (!shunt_ops_add(&sy, syop(parser_ctx(parser), op)))