add new operators to the shunter

This commit is contained in:
afonya2 2025-05-23 20:48:19 +02:00
parent 27000668c2
commit b56bb9a48c
Signed by: afonya
GPG key ID: EBB9C4CAFAAFB2DC

View file

@ -96,9 +96,10 @@ fn read_call(variable: ASTPart, pos: &mut usize, input: &Vec<Token>) -> ASTPart
fn operator_precedence(op: &str) -> i64 {
match op {
"|" | "&" => 1,
"+" | "-" => 2,
"*" | "/" | "%" => 3,
"^" => 4,
"==" | "!=" | "<=" | ">=" => 2,
"+" | "-" => 3,
"*" | "/" | "%" => 4,
"^" => 5,
_ => 0
}
}
@ -106,9 +107,7 @@ fn operator_precedence(op: &str) -> i64 {
fn shunt(input: Vec<ASTPart>) -> ASTPart {
let mut output: Vec<ASTPart> = vec![];
let mut stack: Vec<ASTPart> = vec![];
println!("Shunting input: {:?}", input);
for part in input {
println!("Shunting part: {:?}", part);
match &part {
ASTPart::String(_) => {
output.push(part);
@ -151,7 +150,6 @@ fn shunt(input: Vec<ASTPart>) -> ASTPart {
while stack.len() > 0 {
output.push(stack.pop().unwrap());
}
println!("Shunting output: {:?}\n\n", output);
let mut i = 0;
while i < output.len() {
match &output[i] {