ast module
This commit is contained in:
+37
-10
@@ -1,11 +1,38 @@
|
|||||||
pub mod AST {
|
pub trait Stmt {}
|
||||||
pub enum NodeType {
|
pub trait Expr: Stmt {}
|
||||||
Program,
|
|
||||||
NumericLiteral,
|
pub enum NodeType {
|
||||||
Identifier,
|
Program(Program),
|
||||||
BinaryExpression,
|
NumericLiteral(NumericLiteral),
|
||||||
CallExperssion,
|
Identifier(Identifier),
|
||||||
UnaryExpression,
|
BinaryExpr(BinaryExpr),
|
||||||
FunctionDeclaration,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct Program {
|
||||||
|
pub body: Vec<NodeType>,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct BinaryExpr {
|
||||||
|
pub left: Box<NodeType>,
|
||||||
|
pub right: Box<NodeType>,
|
||||||
|
pub operator: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct Identifier {
|
||||||
|
pub symbol: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct NumericLiteral {
|
||||||
|
pub value: f64,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Stmt for Program {}
|
||||||
|
|
||||||
|
impl Stmt for NumericLiteral {}
|
||||||
|
impl Expr for NumericLiteral {}
|
||||||
|
|
||||||
|
impl Stmt for Identifier {}
|
||||||
|
impl Expr for Identifier {}
|
||||||
|
|
||||||
|
impl Stmt for BinaryExpr {}
|
||||||
|
impl Expr for BinaryExpr {}
|
||||||
|
|||||||
Reference in New Issue
Block a user