use std::fmt;
#[derive(Debug, Clone, PartialEq)]
pub enum Expr {
Number(f64),
Var(String),
BinaryOp {
op: BinOp,
left: Box<Expr>,
right: Box<Expr>,
},
Assign {
name: String,
expr: Box<Expr>,
},
Lambda {
param: String,
body: Box<Expr>,
},
Call {
func: Box<Expr>,
args: Vec<Expr>,
},
}
#[derive(Debug, Clone, PartialEq)]
pub enum BinOp {
Add,
Sub,
Mul,
Div,
}
impl fmt::Display for BinOp {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
BinOp::Add => write!(f, "+"),
BinOp::Sub => write!(f, "-"),
BinOp::Mul => write!(f, "*"),
BinOp::Div => write!(f, "/"),
}
}
}