wow it works
This commit is contained in:
commit
00e2260bb3
7 changed files with 237 additions and 0 deletions
28
src/ast.rs
Normal file
28
src/ast.rs
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
use std::collections::hash_map::DefaultHasher;
|
||||
use std::hash::{Hash, Hasher};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub enum Prim {
|
||||
Sin,
|
||||
Cos,
|
||||
Triple, // 3 * x
|
||||
AddPair, // (a,b) -> a + b
|
||||
Input, // переменная x
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub enum ExprAst {
|
||||
Atom(Prim),
|
||||
Composition(Box<ExprAst>, Box<ExprAst>), // g ∘ f
|
||||
Junction(Box<ExprAst>, Box<ExprAst>), // (f, g)
|
||||
}
|
||||
|
||||
pub fn ast_input() -> ExprAst {
|
||||
ExprAst::Atom(Prim::Input)
|
||||
}
|
||||
|
||||
pub fn hash_ast(e: &ExprAst) -> u64 {
|
||||
let mut h = DefaultHasher::new();
|
||||
e.hash(&mut h);
|
||||
h.finish()
|
||||
}
|
||||
Loading…
Reference in a new issue