safe commit, because actually reading about good practices now, so rework incomming uwu
This commit is contained in:
parent
05ebc02909
commit
2f99969f12
9 changed files with 57 additions and 20 deletions
62
src/language_frontend/ast/ast.rs
Normal file
62
src/language_frontend/ast/ast.rs
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
/// Abstract Syntax Tree
|
||||
#[derive(Debug)]
|
||||
pub enum Expression<'src> {
|
||||
VariableName(&'src str),
|
||||
Integer(i64),
|
||||
Float(f64),
|
||||
String(String),
|
||||
Bool(bool),
|
||||
|
||||
Negatation(Box<Expression<'src>>),
|
||||
Add(Box<Expression<'src>>, Box<Expression<'src>>),
|
||||
Substract(Box<Expression<'src>>, Box<Expression<'src>>),
|
||||
Multiply(Box<Expression<'src>>, Box<Expression<'src>>),
|
||||
Divide(Box<Expression<'src>>, Box<Expression<'src>>),
|
||||
|
||||
Var {
|
||||
name: &'src str,
|
||||
rhs: Box<Expression<'src>>,
|
||||
then: Box<Expression<'src>>,
|
||||
},
|
||||
|
||||
Function {
|
||||
name: &'src str,
|
||||
args: Vec<&'src str>,
|
||||
body: Box<Expression<'src>>,
|
||||
then: Box<Expression<'src>>,
|
||||
},
|
||||
|
||||
Unit
|
||||
}
|
||||
|
||||
impl<'src> Expression<'src> {
|
||||
pub fn evaluate(&self) -> String {
|
||||
match self {
|
||||
Expression::VariableName(_) => todo!(),
|
||||
|
||||
Expression::Integer(_) => todo!(),
|
||||
|
||||
Expression::Float(_) => todo!(),
|
||||
|
||||
Expression::String(_) => todo!(),
|
||||
|
||||
Expression::Bool(_) => todo!(),
|
||||
|
||||
Expression::Negatation(expression) => todo!(),
|
||||
|
||||
Expression::Add(expression, expression1) => todo!(),
|
||||
|
||||
Expression::Substract(expression, expression1) => todo!(),
|
||||
|
||||
Expression::Multiply(expression, expression1) => todo!(),
|
||||
|
||||
Expression::Divide(expression, expression1) => todo!(),
|
||||
|
||||
Expression::Var { name, rhs, then } => todo!(),
|
||||
|
||||
Expression::Function { name, args, body, then } => todo!(),
|
||||
|
||||
Expression::Unit => todo!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
2
src/language_frontend/ast/mod.rs
Normal file
2
src/language_frontend/ast/mod.rs
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
pub mod ast;
|
||||
pub mod op;
|
||||
19
src/language_frontend/ast/op.rs
Normal file
19
src/language_frontend/ast/op.rs
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
#[derive(Debug, Clone)]
|
||||
pub enum Op {
|
||||
Add,
|
||||
Subtract,
|
||||
Multiply,
|
||||
Divide,
|
||||
}
|
||||
|
||||
impl Op {
|
||||
pub fn eval(&self) -> String {
|
||||
let text: &str = match self {
|
||||
Op::Add => "+",
|
||||
Op::Subtract => "-",
|
||||
Op::Multiply => "*",
|
||||
Op::Divide => "/",
|
||||
};
|
||||
text.to_string()
|
||||
}
|
||||
}
|
||||
1
src/language_frontend/mod.rs
Normal file
1
src/language_frontend/mod.rs
Normal file
|
|
@ -0,0 +1 @@
|
|||
pub mod ast;
|
||||
Loading…
Add table
Add a link
Reference in a new issue