Fix bug with assignment precedence
This commit is contained in:
parent
630420b114
commit
9ec1e00afa
@ -80,8 +80,8 @@ fn binop_precedences(s: &str) -> i32 {
|
|||||||
"<" => 20,
|
"<" => 20,
|
||||||
"<=" => 20,
|
"<=" => 20,
|
||||||
"==" => 40,
|
"==" => 40,
|
||||||
"=" => 10,
|
|
||||||
"<=>" => 30,
|
"<=>" => 30,
|
||||||
|
"=" => 5, // Assignment shoudl have highest precedence
|
||||||
_ => default,
|
_ => default,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ fn evaluate_input(input: &str) -> Result<String, String> {
|
|||||||
let mut symbol_table = SymbolTable::new();
|
let mut symbol_table = SymbolTable::new();
|
||||||
symbol_table.process_ast(&ast).unwrap();
|
symbol_table.process_ast(&ast).unwrap();
|
||||||
let reduced_ir = crate::reduced_ir::reduce(&ast, &symbol_table);
|
let reduced_ir = crate::reduced_ir::reduce(&ast, &symbol_table);
|
||||||
|
reduced_ir.debug(&symbol_table);
|
||||||
let mut state = State::new();
|
let mut state = State::new();
|
||||||
let mut outputs = state.evaluate(reduced_ir, true);
|
let mut outputs = state.evaluate(reduced_ir, true);
|
||||||
outputs.pop().unwrap()
|
outputs.pop().unwrap()
|
||||||
@ -21,10 +22,7 @@ fn eval_assert(input: &str, expected: &str) {
|
|||||||
fn test_basic_eval() {
|
fn test_basic_eval() {
|
||||||
eval_assert("1 + 2", "3");
|
eval_assert("1 + 2", "3");
|
||||||
eval_assert("let mut a = 1; a = 2", "()");
|
eval_assert("let mut a = 1; a = 2", "()");
|
||||||
/*
|
eval_assert("let mut a = 1; a = a + 2; a", "3");
|
||||||
test_in_fresh_env!("let mut a = 1; a = 2; a", "2");
|
|
||||||
test_in_fresh_env!(r#"("a", 1 + 2)"#, r#"("a", 3)"#);
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
Loading…
Reference in New Issue
Block a user