Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support subtraction operation in array symbolic value #251

Merged
merged 2 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/mast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ impl Symbolic {
}
Symbolic::Generic(g) => gens.get(&g.value),
Symbolic::Add(a, b) => a.eval(gens, tast) + b.eval(gens, tast),
Symbolic::Sub(a, b) => a.eval(gens, tast) - b.eval(gens, tast),
Symbolic::Mul(a, b) => a.eval(gens, tast) * b.eval(gens, tast),
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/parser/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ pub enum Symbolic {
/// Generic parameter
Generic(Ident),
Add(Box<Symbolic>, Box<Symbolic>),
Sub(Box<Symbolic>, Box<Symbolic>),
Mul(Box<Symbolic>, Box<Symbolic>),
}

Expand All @@ -198,6 +199,7 @@ impl Display for Symbolic {
Symbolic::Constant(ident) => write!(f, "{}", ident.value),
Symbolic::Generic(ident) => write!(f, "{}", ident.value),
Symbolic::Add(lhs, rhs) => write!(f, "{} + {}", lhs, rhs),
Symbolic::Sub(lhs, rhs) => write!(f, "{} - {}", lhs, rhs),
Symbolic::Mul(lhs, rhs) => write!(f, "{} * {}", lhs, rhs),
}
}
Expand All @@ -219,7 +221,7 @@ impl Symbolic {
Symbolic::Generic(ident) => {
generics.insert(ident.value.clone());
}
Symbolic::Add(lhs, rhs) | Symbolic::Mul(lhs, rhs) => {
Symbolic::Add(lhs, rhs) | Symbolic::Mul(lhs, rhs) | Symbolic::Sub(lhs, rhs) => {
generics.extend(lhs.extract_generics());
generics.extend(rhs.extract_generics());
}
Expand Down Expand Up @@ -251,6 +253,7 @@ impl Symbolic {
// no protected flags are needed, as this is based on expression nodes which already ordered the operations
match op {
Op2::Addition => Ok(Symbolic::Add(Box::new(lhs), Box::new(rhs?))),
Op2::Subtraction => Ok(Symbolic::Sub(Box::new(lhs), Box::new(rhs?))),
Op2::Multiplication => Ok(Symbolic::Mul(Box::new(lhs), Box::new(rhs?))),
_ => Err(Error::new(
"mast",
Expand Down
Loading