Value parseAdditiveExpression(void) { Value v1, v2; v1 = parseMultiplicativeExpression(); while (token == TOK_PLUS || token == TOK_MINUS) { if (token == TOK_PLUS) { getToken(); v2 = parseMultiplicativeExpression(); if (v1.sym != NULL && v2.sym != NULL) { error("addition of symbols not supported, line %d", lineno); } if (v2.sym != NULL) { v1.sym = v2.sym; } v1.con += v2.con; } else if (token == TOK_MINUS) { getToken(); v2 = parseMultiplicativeExpression(); if (v2.sym != NULL) { error("subtraction of symbols not supported, line %d", lineno); } v1.con -= v2.con; } } return v1; }
bool Expr::parseAdditiveExpression() { PARSER_FLOW_TRACER(); /* right associative */ FAIL_IF_NOT(parseMultiplicativeExpression()); while (IS_ADDI_EXPR_OPER(ahead().type())) { Model::ExprBinary::Ptr result = new Model::ExprBinary; result->setLeftOperand(model()); result->setBinaryOperator(tokenToBinary(ahead().type())); next(); FAIL_IF_NOT(parseMultiplicativeExpression()); result->setRightOperand(model()); setModel(result); } return true; }