add new operators to the shunter
This commit is contained in:
parent
27000668c2
commit
b56bb9a48c
1 changed files with 4 additions and 6 deletions
|
@ -96,9 +96,10 @@ fn read_call(variable: ASTPart, pos: &mut usize, input: &Vec<Token>) -> ASTPart
|
||||||
fn operator_precedence(op: &str) -> i64 {
|
fn operator_precedence(op: &str) -> i64 {
|
||||||
match op {
|
match op {
|
||||||
"|" | "&" => 1,
|
"|" | "&" => 1,
|
||||||
"+" | "-" => 2,
|
"==" | "!=" | "<=" | ">=" => 2,
|
||||||
"*" | "/" | "%" => 3,
|
"+" | "-" => 3,
|
||||||
"^" => 4,
|
"*" | "/" | "%" => 4,
|
||||||
|
"^" => 5,
|
||||||
_ => 0
|
_ => 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -106,9 +107,7 @@ 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);
|
||||||
|
@ -151,7 +150,6 @@ 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] {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue