-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from coco33920/symbolic_relex
Symbolic relex
- Loading branch information
Showing
23 changed files
with
3,479 additions
and
1,326 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ name: Rust | |
|
||
on: | ||
push: | ||
branches: [ "mistress" ] | ||
pull_request: | ||
branches: [ "mistress" ] | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,5 @@ release: | |
cargo build --release | ||
test: | ||
cargo test | ||
publish: | ||
cargo publish |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
pub mod rationals; | ||
pub mod symbolic; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
use crate::parsing::ast::Parameters; | ||
use crate::parsing::ast::Parameters::*; | ||
|
||
pub fn size(p: &Parameters) -> i32 { | ||
match p { | ||
Null | ||
| Int(_) | ||
| Str(_) | ||
| Float(_) | ||
| Identifier(_) | ||
| PlusOperation | ||
| MinusOperation | ||
| MultiplicationOperation | ||
| DivideOperation | ||
| Assign | ||
| ExpoOperation | ||
| GreaterOperation | ||
| GreaterOrEqualOperation | ||
| LesserOperation | ||
| LesserOrEqualOperation | ||
| Equal | ||
| Bool(_) | ||
| Rational(_) | ||
| OrOperation | ||
| AndOperation | ||
| Not | ||
| Vector(_) | ||
| InterpreterVector(_) => 0, | ||
Plus(x, y) => 1 + size(x) + size(y), | ||
Var(x, _, _) => 1 + size(x), | ||
Mul(x, y) => 1 + size(x) + size(y), | ||
Div(x, y) => 1 + size(x) + size(y), | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
|
||
use crate::{ | ||
exact_math::rationals::Rationals, | ||
parsing::ast::{ | ||
Ast, | ||
Parameters::{self, *}, | ||
}, | ||
}; | ||
|
||
use super::size; | ||
#[test] | ||
fn test_leaf() { | ||
let v = vec![ | ||
Null, | ||
Int(1), | ||
Str("".to_string()), | ||
Float(1.0), | ||
Identifier("".to_string()), | ||
PlusOperation, | ||
MinusOperation, | ||
MultiplicationOperation, | ||
DivideOperation, | ||
Assign, | ||
ExpoOperation, | ||
GreaterOperation, | ||
GreaterOrEqualOperation, | ||
LesserOperation, | ||
LesserOrEqualOperation, | ||
Equal, | ||
Bool(false), | ||
Rational(Rationals::new(10, 10)), | ||
OrOperation, | ||
AndOperation, | ||
Not, | ||
Vector(Box::from(vec![Ast::Nil])), | ||
InterpreterVector(Box::from(vec![Null])), | ||
]; | ||
|
||
let should = vec![ | ||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
0, 0, 0, 0, 0, | ||
]; | ||
|
||
let _ = v | ||
.into_iter() | ||
.map(|f| size(&f)) | ||
.zip(should) | ||
.for_each(|(x, y)| assert_eq!(x, y)); | ||
} | ||
|
||
#[test] | ||
fn test_size() { | ||
let should = 2; | ||
let tree = Plus( | ||
Box::from(Plus( | ||
Box::from(Parameters::Int(1)), | ||
Box::from(Parameters::Int(2)), | ||
)), | ||
Box::from(Parameters::Int(3)), | ||
); | ||
let result = size(&tree); | ||
assert_eq!(result, should); | ||
} | ||
#[test] | ||
fn test_size_mul() { | ||
let should = 2; | ||
let tree = Mul( | ||
Box::from(Plus( | ||
Box::from(Parameters::Int(1)), | ||
Box::from(Parameters::Int(2)), | ||
)), | ||
Box::from(Parameters::Int(3)), | ||
); | ||
let result = size(&tree); | ||
assert_eq!(result, should); | ||
} | ||
#[test] | ||
fn test_size_var() { | ||
let should = 1; | ||
let tree = Var(Box::from(Parameters::Int(1)), 1, "s".to_string()); | ||
let result = size(&tree); | ||
assert_eq!(result, should); | ||
} | ||
} |
Oops, something went wrong.