42 lines
845 B
Rust
42 lines
845 B
Rust
|
|
#[derive(Debug, Clone)]
|
|
pub enum Token {
|
|
Negation,
|
|
Conjunction,
|
|
Disjunction,
|
|
ExclusiveDisjunction,
|
|
MaterialCondition,
|
|
LogicalEquivalence
|
|
}
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub enum Node<T> {
|
|
Leaf(T),
|
|
Unary {
|
|
operator: Token,
|
|
operand: Box<Node<T>>
|
|
},
|
|
Binary {
|
|
operator: Token,
|
|
lhs: Box<Node<T>>,
|
|
rhs: Box<Node<T>>,
|
|
},
|
|
}
|
|
|
|
pub fn add_unary_node<T>(stack: &mut Vec<Node<T>>, token: Token) {
|
|
let operand = Box::new(stack.pop().unwrap());
|
|
stack.push(Node::Unary {
|
|
operator: token,
|
|
operand,
|
|
});
|
|
}
|
|
|
|
pub fn add_binary_node<T>(stack: &mut Vec<Node<T>>, token: Token) {
|
|
let lhs = Box::new(stack.pop().unwrap());
|
|
let rhs = Box::new(stack.pop().unwrap());
|
|
stack.push(Node::Binary {
|
|
operator: token,
|
|
lhs,
|
|
rhs
|
|
});
|
|
} |