Remove BinOpType::Not from ast

- Impl. Display for BinOpType & UnOpType
- Impl. scuffed Display for Ast that just uses Debug pretty print
This commit is contained in:
Daniel M 2021-12-29 02:22:03 +01:00
parent 1712dac6d6
commit 12e95ed822
2 changed files with 46 additions and 3 deletions

View File

@ -1,3 +1,5 @@
use std::fmt::Display;
use crate::token::Literal;
/// Binary Operator Types. For operations that have two operands
@ -35,8 +37,6 @@ pub enum BinOpType {
And,
/// Boolean Or "||"
Or,
/// Boolean Not "!"
Not,
/// Boolean Xor "^^"
Xor,
}
@ -108,3 +108,47 @@ impl Ast {
Self { prog }
}
}
impl Display for Ast {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
writeln!(f, "Ast[")?;
for stmt in &self.prog {
writeln!(f, "{:#?},", stmt)?;
}
writeln!(f, "]")
}
}
impl Display for BinOpType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let sop = match self {
BinOpType::Add => "+",
BinOpType::Sub => "-",
BinOpType::Mul => "*",
BinOpType::Div => "/",
BinOpType::Mod => "%",
BinOpType::Eq => "==",
BinOpType::Neq => "!=",
BinOpType::Gt => ">",
BinOpType::Lt => "<",
BinOpType::Ge => ">=",
BinOpType::Le => "<=",
BinOpType::And => "&&",
BinOpType::Or => "||",
BinOpType::Xor => "^^",
};
write!(f, "{}", sop)
}
}
impl Display for UnOpType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let sop = match self {
UnOpType::Neg => "-",
UnOpType::Not => "!",
};
write!(f, "{}", sop)
}
}

View File

@ -83,7 +83,6 @@ impl Interpreter {
BinOpType::And => todo!(),
BinOpType::Or => todo!(),
BinOpType::Not => todo!(),
BinOpType::Xor => todo!(),
};