From 3c0648e4736e5c5638d7fbc973b8e2907bad31ea Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Fri, 10 Aug 2018 17:20:14 -0700 Subject: [PATCH] Fix the assumption that the stack only has infix operators. --- src/parser.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/parser.c b/src/parser.c index 736aa32..1e185a6 100644 --- a/src/parser.c +++ b/src/parser.c @@ -1055,11 +1055,13 @@ libab_result _parse_expression(struct parser_state* state, while (result == LIBAB_SUCCESS && op_stack.tail && _parser_match_is_op(op_stack.tail->data)) { - _parser_find_operator_infix(state, op_stack.tail->data, - &other_operator); + libab_lexer_match* other_token = op_stack.tail->data; + if(other_token->type == TOKEN_OP_INFIX) { + _parser_find_operator_infix(state, op_stack.tail->data, + &other_operator); + } - if (((libab_lexer_match*)op_stack.tail->data)->type == - TOKEN_OP_PREFIX || + if (other_token->type == TOKEN_OP_PREFIX || (operator.associativity == - 1 && operator.precedence <= other_operator.precedence) || (operator.associativity == 1 &&