Start of expression parsing

This commit is contained in:
2023-07-04 02:49:29 -05:00
parent 2a9bfb342b
commit 2aac110900
3 changed files with 276 additions and 7 deletions
+72
View File
@@ -53,3 +53,75 @@ pub struct Argname {
pub name: String,
pub typename: Option<String>,
}
#[derive(Eq, PartialEq, Clone, Debug)]
pub struct Block {
pub statements: Vec<Statement>,
}
#[derive(Eq, PartialEq, Clone, Debug)]
pub enum Statement {
Return(Return),
Assignment(Assignment),
Call(Call),
VarDecl(VarDecl),
Conditional(Conditional),
WhileLoop(WhileLoop),
RepeatLoop(RepeatLoop),
}
#[derive(Eq, PartialEq, Clone, Debug)]
pub struct Return {}
#[derive(Eq, PartialEq, Clone, Debug)]
pub struct Assignment {}
#[derive(Eq, PartialEq, Clone, Debug)]
pub struct Call {}
#[derive(Eq, PartialEq, Clone, Debug)]
pub struct VarDecl {}
#[derive(Eq, PartialEq, Clone, Debug)]
pub struct Conditional {}
#[derive(Eq, PartialEq, Clone, Debug)]
pub struct WhileLoop {}
#[derive(Eq, PartialEq, Clone, Debug)]
pub struct RepeatLoop {}
/// One of the five arithmetical operators
#[derive(Debug, PartialEq, Copy, Clone)]
pub enum Operator {
Add,
Sub,
Mul,
Div,
Mod,
}
#[derive(PartialEq, Clone, Debug)]
pub enum Node {
Number(i32),
Call(Call),
ArrayRef(ArrayRef),
Name(String),
Address(String),
Expr(Box<Node>, Vec<(Operator, Node)>),
}
impl From<i32> for Node {
fn from(val: i32) -> Self {
Self::Number(val)
}
}
impl From<&str> for Node {
fn from(s: &str) -> Self {
Self::Name(String::from(s))
}
}
#[derive(Eq, PartialEq, Clone, Debug)]
pub struct ArrayRef {}