Fix bug in shunting yard implementation.

This commit is contained in:
Danila Fedorin 2018-08-17 19:10:48 -07:00
parent 37593abe40
commit 8c9acafc93

View File

@ -1056,16 +1056,15 @@ libab_result _parse_expression(struct parser_state* state,
while (result == LIBAB_SUCCESS && op_stack.tail && while (result == LIBAB_SUCCESS && op_stack.tail &&
_parser_match_is_op(op_stack.tail->data)) { _parser_match_is_op(op_stack.tail->data)) {
libab_lexer_match* other_token = op_stack.tail->data; libab_lexer_match* other_token = op_stack.tail->data;
if(other_token->type == TOKEN_OP_INFIX) { if(other_token->type == TOKEN_OP_INFIX || other_token->type == TOKEN_OP_RESERVED) {
_parser_find_operator_infix(state, op_stack.tail->data, _parser_find_operator_infix(state, other_token, &other_operator);
&other_operator);
} }
if (other_token->type == TOKEN_OP_PREFIX || if (other_token->type == TOKEN_OP_PREFIX ||
(operator.associativity == - 1 && (operator.associativity == - 1 &&
operator.precedence <= other_operator.precedence) || operator.precedence <= other_operator.precedence) ||
(operator.associativity == 1 && (operator.associativity == 1 &&
operator.precedence<other_operator.precedence)) { operator.precedence < other_operator.precedence)) {
libab_lexer_match* match = ll_poptail(&op_stack); libab_lexer_match* match = ll_poptail(&op_stack);
result = _parser_append_op_node(state, match, &out_stack); result = _parser_append_op_node(state, match, &out_stack);
} else { } else {