mirror of
https://github.com/Noratrieb/dilaria.git
synced 2026-01-16 02:15:01 +01:00
add break to lex and create first ast
This commit is contained in:
parent
40a7aaac71
commit
186eb71a50
4 changed files with 110 additions and 2 deletions
101
src/ast.rs
Normal file
101
src/ast.rs
Normal file
|
|
@ -0,0 +1,101 @@
|
|||
pub struct Block(pub Vec<Stmt>);
|
||||
|
||||
pub enum Stmt {
|
||||
VariableDecl(VariableDecl),
|
||||
Assignment(Assignment),
|
||||
FnDecl(FnDecl),
|
||||
Break,
|
||||
Return(Option<Expr>),
|
||||
Conditional(Conditional),
|
||||
Loop(Block),
|
||||
WhileLoop(WhileLoop),
|
||||
ForLoop(Box<ForLoop>),
|
||||
Expr(Expr),
|
||||
}
|
||||
|
||||
pub struct VariableDecl {
|
||||
name: String,
|
||||
init: Option<Expr>,
|
||||
}
|
||||
|
||||
pub struct Assignment {
|
||||
pub lhs: Expr,
|
||||
pub rhs: Expr,
|
||||
}
|
||||
|
||||
pub struct FnDecl {
|
||||
pub name: String,
|
||||
pub params: Vec<String>,
|
||||
pub body: Block,
|
||||
}
|
||||
|
||||
pub struct Conditional {
|
||||
pub condition: Expr,
|
||||
pub body: Block,
|
||||
pub else_block: Option<Block>,
|
||||
}
|
||||
|
||||
pub struct WhileLoop {
|
||||
pub cond: Expr,
|
||||
pub body: Block,
|
||||
}
|
||||
|
||||
pub struct ForLoop {
|
||||
pub init: Stmt,
|
||||
pub cond: Expr,
|
||||
pub post: Stmt,
|
||||
pub body: Block,
|
||||
}
|
||||
|
||||
pub enum Expr {
|
||||
Literal(Literal),
|
||||
UnaryOp,
|
||||
BinaryOp,
|
||||
Call,
|
||||
}
|
||||
|
||||
pub enum Literal {
|
||||
String(String),
|
||||
Number(f64),
|
||||
Array(Vec<Expr>),
|
||||
Object, // todo
|
||||
Boolean(bool),
|
||||
Null,
|
||||
}
|
||||
|
||||
pub struct UnaryOp {
|
||||
pub expr: Expr,
|
||||
pub kind: UnaryOpKind,
|
||||
}
|
||||
|
||||
pub enum UnaryOpKind {
|
||||
Not,
|
||||
Neg,
|
||||
}
|
||||
|
||||
pub struct BinaryOp {
|
||||
pub lhs: Expr,
|
||||
pub rhs: Expr,
|
||||
pub kind: BinaryOpKind,
|
||||
}
|
||||
|
||||
pub enum BinaryOpKind {
|
||||
And,
|
||||
Or,
|
||||
Equal,
|
||||
GreaterEqual,
|
||||
Greater,
|
||||
LessEqual,
|
||||
Less,
|
||||
NotEqual,
|
||||
Add,
|
||||
Sub,
|
||||
Mul,
|
||||
Div,
|
||||
Mod,
|
||||
}
|
||||
|
||||
pub enum Call {
|
||||
Function(Expr, Vec<Expr>),
|
||||
Field(Expr, Vec<Expr>),
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue