-
Notifications
You must be signed in to change notification settings - Fork 9
Added parser for polynomial expressions for AST generation. #63
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
Conversation
|
@dawnandrew100 , I implemented pratt parsing for now, yet I believe this doesn't comply with the architecture of the project, I'll be trying to fit this in as you suggest. |
|
also, what sort of test do you expect? |
|
@shri-acha So, some things that I think should be tested for are:
|
|
@dawnandrew100 |
|
@shri-acha i think in the case of The implied multiplication between the integer/float and variable is pretty standard, so I don't think we should require that there be an explicit |
|
Oh right, sorry about the confusion, I do realize I might've thought too much on it before. |
|
hey @dawnandrew100 , I did add all the tests and made it works for all the valid conditions. I've also created new error variants within We have to work making invalid expressions throw suitable errors, I'd like to know how we could approach on adding checks for errors in expressions. |
|
@shri-acha I'll do a proper look through in the morning, but I did notice that this was an error in the tests #[test]
fn test_multiple_exponents(){
let expr="4x^2^3";
let tok_str = lexer(expr).unwrap();
let result = parser(tok_str, 0.0);
println!("{:?}",result);
assert!(matches!(result,Err(_)));
}But |
|
Sure, I'll fix this test, it seems I've messed up while copy pasting. As for better assert matching, I think |
|
I just saw the suggested structure of Ast from #30, I'll be just refactoring my exisiting parser to support suggested structure. |
|
@shri-acha You don't necessarily need to follow that to a tee. The structure that you have now looks fine The bigger thing with the structs would be the naming conventions and the implemented traits. So if you could rename your struct from The structs should also implement the pub trait PolynomialTraits {
fn parse(input: &str) -> Result<Self, PolynomialError>
where
Self: std::marker::Sized;
fn eval_univariate<F>(&self, point: F) -> Result<f64, PolynomialError>
where
F: Into<f64> + std::clone::Clone + std::fmt::Debug;
fn eval_multivariate<V, S, F>(&self, vars: &V) -> Result<f64, PolynomialError>
where
V: IntoIterator<Item = (S, F)> + std::fmt::Debug + Clone,
S: AsRef<str>,
F: Into<f64>;
fn derivate_univariate(&self) -> Result<Self, PolynomialError>
where
Self: std::marker::Sized;
fn derivate_multivariate<S>(&self, var: S) -> Self
where
S: AsRef<str>;
fn indefinite_integral_univariate(&self) -> Result<Self, PolynomialError>
where
Self: std::marker::Sized;
}You already have the parser, but the evaluation, derivation, and integration for both univariate and multivariate expressions might be a lot to include in just one PR |
|
@dawnandrew100. |
|
@dawnandrew100 , I don't understand |
|
@shri-acha actually I misspoke! We don't need the That's part of SimplePolynomial and PolynomialExtended just so that some of the tests could pass since some of the functions originally returned a Vec<64> or Vec respectively so the tests were built around that. But we don't need that for the
|
|
@shri-acha error[E0433]: failed to resolve: use of unresolved module or unlinked crate `once_cell`
--> /home/runner/work/spindalis/spindalis/spindalis_core/src/polynomials/ast.rs:3:5
|
3 | use once_cell::sync::Lazy;
| ^^^^^^^^^ use of unresolved module or unlinked crate `once_cell`
|
= help: if you wanted to use a crate named `once_cell`, use `cargo add once_cell` to add it to your `Cargo.toml`
warning: unused import: `std::cell::RefCell`
--> /home/runner/work/spindalis/spindalis/spindalis_core/src/polynomials/ast.rs:4:5
|
4 | use std::cell::RefCell;
| ^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(unused_imports)]` (part of `#[warn(unused)]`) on by default
warning: unused variable: `val`
--> /home/runner/work/spindalis/spindalis/spindalis_core/src/polynomials/ast.rs:307:17
|
307 | val => {}
| ^^^ help: if this is intentional, prefix it with an underscore: `_val`
|
= note: `#[warn(unused_variables)]` (part of `#[warn(unused)]`) on by default
For more information about this error, try `rustc --explain E0433`.
warning: `spindalis_core` (lib) generated 2 warnings
error: could not compile `spindalis_core` (lib) due to 1 previous error; 2 warnings emitted |
|
@shri-acha Checks are passing, so just let me know if you're ready to merge this PR and I'll do a proper review 👌 |
|
I'm ready you can review the code. |
Solves the issue, #27.