#[derive(Debug, Clone, PartialEq)]
pub enum Token {
Value(String),
Op(Op),
LParen,
RParen,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum Op {
Plus,
Minus,
Mul,
Div,
Exp,
}
impl Op {
pub fn precedence(self) -> u8 {
match self {
Self::Plus | Self::Minus => 1,
Self::Mul | Self::Div => 2,
Self::Exp => 3,
}
}
pub fn is_left_associative(self) -> bool {
match self {
Self::Plus | Self::Minus | Self::Mul | Self::Div => true,
Self::Exp => false,
}
}
pub fn is_right_associative(self) -> bool {
!self.is_left_associative()
}
}