From: Wolfgang (Blub) Bumiller Date: Fri, 23 Nov 2012 10:57:08 +0000 (+0100) Subject: Parsing of suffix operators, NOTE: applied like prefix operators just to get it commi... X-Git-Tag: 0.1.9~318 X-Git-Url: https://git.xonotic.org/?p=xonotic%2Fgmqcc.git;a=commitdiff_plain;h=4079835c7e75bb2b6a20ebb1f1e91e4c8c362c99 Parsing of suffix operators, NOTE: applied like prefix operators just to get it committed in a compilable state --- diff --git a/lexer.h b/lexer.h index 6990991..eaddb03 100644 --- a/lexer.h +++ b/lexer.h @@ -204,6 +204,9 @@ static const size_t c_operator_count = (sizeof(c_operators) / sizeof(c_operators static const oper_info fte_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, 0 }, /* function call */ { "[", 2, opid1('['), ASSOC_LEFT, 15, 0 }, /* array subscript */ diff --git a/parser.c b/parser.c index 54577ea..3c5d237 100644 --- a/parser.c +++ b/parser.c @@ -900,6 +900,28 @@ static bool parser_sy_pop(parser_t *parser, shunt *sy) (ast_expression*)parser_const_float(parser, 1)); } break; + case opid3('S','+','+'): + case opid3('S','-','-'): + /* prefix ++ */ + if (exprs[0]->expression.vtype != TYPE_FLOAT) { + ast_type_to_string(exprs[0], ty1, sizeof(ty1)); + parseerror(parser, "invalid type for prefix increment: %s", ty1); + return false; + } + if (op->id == opid3('+','+','P')) + addop = INSTR_ADD_F; + else + addop = INSTR_SUB_F; + if (ast_istype(exprs[0], ast_entfield)) { + out = (ast_expression*)ast_binstore_new(ctx, INSTR_STOREP_F, addop, + exprs[0], + (ast_expression*)parser_const_float(parser, 1)); + } else { + out = (ast_expression*)ast_binstore_new(ctx, INSTR_STORE_F, addop, + exprs[0], + (ast_expression*)parser_const_float(parser, 1)); + } + break; case opid2('+','='): case opid2('-','='): if (exprs[0]->expression.vtype != exprs[1]->expression.vtype || @@ -1279,13 +1301,12 @@ static ast_expression* parse_expression_leave(parser_t *parser, bool stopatcomma else { /* classify the operator */ - /* TODO: suffix operators */ const oper_info *op; const oper_info *olast = NULL; size_t o; for (o = 0; o < operator_count; ++o) { if ((!(operators[o].flags & OP_PREFIX) == wantop) && - !(operators[o].flags & OP_SUFFIX) && /* remove this */ + /* !(operators[o].flags & OP_SUFFIX) && / * remove this */ !strcmp(parser_tokval(parser), operators[o].op)) { break; @@ -1379,7 +1400,7 @@ static ast_expression* parse_expression_leave(parser_t *parser, bool stopatcomma } else { DEBUGSHUNTDO(con_out("push operator %s\n", op->op)); vec_push(sy.ops, syop(parser_ctx(parser), op)); - wantop = false; + wantop = !!(op->flags & OP_SUFFIX); } } if (!parser_next(parser)) {