fix: parenthesis

This commit is contained in:
afonya2 2025-05-23 20:35:57 +02:00
parent b074f18648
commit b4886eff87
Signed by: afonya
GPG key ID: EBB9C4CAFAAFB2DC
2 changed files with 5 additions and 2 deletions

View file

@ -106,7 +106,9 @@ fn operator_precedence(op: &str) -> i64 {
fn shunt(input: Vec<ASTPart>) -> ASTPart { fn shunt(input: Vec<ASTPart>) -> ASTPart {
let mut output: Vec<ASTPart> = vec![]; let mut output: Vec<ASTPart> = vec![];
let mut stack: Vec<ASTPart> = vec![]; let mut stack: Vec<ASTPart> = vec![];
println!("Shunting input: {:?}", input);
for part in input { for part in input {
println!("Shunting part: {:?}", part);
match &part { match &part {
ASTPart::String(_) => { ASTPart::String(_) => {
output.push(part); output.push(part);
@ -126,7 +128,7 @@ fn shunt(input: Vec<ASTPart>) -> ASTPart {
ASTPart::Operation(op) => { ASTPart::Operation(op) => {
if *op.left != ASTPart::NOOP && *op.right != ASTPart::NOOP { if *op.left != ASTPart::NOOP && *op.right != ASTPart::NOOP {
output.push(part); output.push(part);
break; continue;
} }
while stack.len() > 0 { while stack.len() > 0 {
let top = &stack[stack.len()-1]; let top = &stack[stack.len()-1];
@ -149,6 +151,7 @@ fn shunt(input: Vec<ASTPart>) -> ASTPart {
while stack.len() > 0 { while stack.len() > 0 {
output.push(stack.pop().unwrap()); output.push(stack.pop().unwrap());
} }
println!("Shunting output: {:?}\n\n", output);
let mut i = 0; let mut i = 0;
while i < output.len() { while i < output.len() {
match &output[i] { match &output[i] {

View file

@ -1,4 +1,4 @@
gethelj a = 1 gethelj a = 1
gethelj b = a + 2 gethelj b = (a + 2) * 3
ugass(a,b) ugass(a,b)
gethelj c = piszv & nem piszv gethelj c = piszv & nem piszv