#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 },
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) {
break;
}
}
- wantop = false;
if (o == operator_count) {
/* no operator found... must be the end of the statement */
break;
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;