From: Wolfgang (Blub) Bumiller Date: Sun, 11 Nov 2012 15:43:16 +0000 (+0100) Subject: array index opening-paren can now return TOKEN_OPERATOR, partially handled in SYA X-Git-Tag: 0.1~19^2~30 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=2994d308a04bfcca8d94cada14c20cc00403d960;p=xonotic%2Fgmqcc.git array index opening-paren can now return TOKEN_OPERATOR, partially handled in SYA --- diff --git a/lexer.c b/lexer.c index 9f1fc4e..e68af81 100644 --- 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 '#': diff --git a/parser.c b/parser.c index 076d9df..12241cb 100644 --- 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)))