feat(maths::evaluator): prep evaluator

This commit is contained in:
gbrochar 2023-08-07 17:29:28 +02:00
parent 5fdc0a1231
commit f9833263ef
4 changed files with 18 additions and 0 deletions

View File

@ -7,6 +7,11 @@ fn main() {
println!("Error during parsing: {e}"); println!("Error during parsing: {e}");
process::exit(1); process::exit(1);
}); });
println!("{:?}", equation);
let is_equation = computorv1::maths::evaluator::is_equation(&equation);
let evaluated = computorv1::maths::evaluator::evaluate(equation); let evaluated = computorv1::maths::evaluator::evaluate(equation);
computorv1::pretty(evaluated); computorv1::pretty(evaluated);
if is_equation {
computorv1::maths::solver::solve(evaluated);
}
} }

View File

@ -1,6 +1,7 @@
use std::ops; use std::ops;
pub mod evaluator; pub mod evaluator;
pub mod solver;
//TODO slow ? check Stein's algorithm (binaryGCD) //TODO slow ? check Stein's algorithm (binaryGCD)
fn gcd(a: i128, b: i128) -> i128 { fn gcd(a: i128, b: i128) -> i128 {

View File

@ -147,3 +147,10 @@ pub fn evaluate(ast: Node) -> Vec<GaussianRational> {
Node::Leaf(value) => value, Node::Leaf(value) => value,
} }
} }
pub fn is_equation(ast: &Node) -> bool {
match ast {
Node::Binary { operator, lhs: _, rhs: _ } => *operator == Token::Equal(),
_ => false,
}
}

5
src/maths/solver.rs Normal file
View File

@ -0,0 +1,5 @@
use super::*;
pub fn solve(equation: Vec<GaussianRational>) -> Vec<GaussianRational> {
vec![]
}