Fix operator precedence parser (#4947)

This commit is contained in:
JT
2022-03-25 16:23:08 +13:00
committed by GitHub
parent b007290a4e
commit d122827a30
2 changed files with 33 additions and 1 deletions

View File

@ -4019,7 +4019,7 @@ pub fn parse_math_expression(
);
error = error.or(err);
if op_prec <= last_prec && expr_stack.len() > 1 {
while op_prec <= last_prec && expr_stack.len() > 1 {
// Collapse the right associated operations first
// so that we can get back to a stack with a lower precedence
let mut rhs = expr_stack
@ -4029,6 +4029,14 @@ pub fn parse_math_expression(
.pop()
.expect("internal error: expression stack empty");
last_prec = op.precedence();
if last_prec < op_prec {
expr_stack.push(op);
expr_stack.push(rhs);
break;
}
let mut lhs = expr_stack
.pop()
.expect("internal error: expression stack empty");