tokenizer.expect("}");
}
-RefPtr<Expression> Parser::parse_expression(unsigned precedence)
+RefPtr<Expression> Parser::parse_expression(const Operator *outer_oper)
{
+ unsigned outer_precedence = (outer_oper ? outer_oper->precedence+(outer_oper->assoc==Operator::RIGHT_TO_LEFT) : 20);
RefPtr<Expression> left;
VariableReference *left_var = 0;
while(1)
if(token==i->token && (!left || i->type!=Operator::PREFIX) && (left || i->type!=Operator::POSTFIX))
oper = i;
- bool lower_precedence = (oper && oper->type!=Operator::PREFIX && precedence && oper->precedence>=precedence);
+ bool lower_precedence = (oper && oper->type!=Operator::PREFIX && oper->precedence>=outer_precedence);
if(token==";" || token==")" || token=="]" || token=="," || lower_precedence)
{
if(left)
RefPtr<UnaryExpression> unary = create_node<UnaryExpression>();
unary->oper = oper;
tokenizer.parse_token();
- unary->expression = parse_expression(oper->precedence);
+ unary->expression = parse_expression(oper);
left = unary;
}
else
tokenizer.expect("]");
}
else
- binary->right = parse_expression(oper.precedence+(oper.assoc==Operator::RIGHT_TO_LEFT));
+ binary->right = parse_expression(&oper);
return binary;
}
RefPtr<Layout> parse_layout();
template<typename T>
void parse_block(Block &, bool, RefPtr<T> (Parser::*)());
- RefPtr<Expression> parse_expression(unsigned = 0);
+ RefPtr<Expression> parse_expression(const Operator * = 0);
RefPtr<Literal> parse_literal();
RefPtr<BinaryExpression> parse_binary(const RefPtr<Expression> &, const Operator &);
RefPtr<FunctionCall> parse_function_call(const VariableReference &);