Fix bug with assignment precedence

This commit is contained in:
Greg Shuflin 2021-10-24 23:05:47 -07:00
parent 630420b114
commit 9ec1e00afa
2 changed files with 3 additions and 5 deletions

View File

@ -80,8 +80,8 @@ fn binop_precedences(s: &str) -> i32 {
"<" => 20,
"<=" => 20,
"==" => 40,
"=" => 10,
"<=>" => 30,
"=" => 5, // Assignment shoudl have highest precedence
_ => default,
}
}

View File

@ -8,6 +8,7 @@ fn evaluate_input(input: &str) -> Result<String, String> {
let mut symbol_table = SymbolTable::new();
symbol_table.process_ast(&ast).unwrap();
let reduced_ir = crate::reduced_ir::reduce(&ast, &symbol_table);
reduced_ir.debug(&symbol_table);
let mut state = State::new();
let mut outputs = state.evaluate(reduced_ir, true);
outputs.pop().unwrap()
@ -21,10 +22,7 @@ fn eval_assert(input: &str, expected: &str) {
fn test_basic_eval() {
eval_assert("1 + 2", "3");
eval_assert("let mut a = 1; a = 2", "()");
/*
test_in_fresh_env!("let mut a = 1; a = 2; a", "2");
test_in_fresh_env!(r#"("a", 1 + 2)"#, r#"("a", 3)"#);
*/
eval_assert("let mut a = 1; a = a + 2; a", "3");
}
#[test]