Initialize Aster project with basic structure, including Cargo configuration, lexer, parser, interpreter, and AST definitions. Add a sample script and README documentation. Implement basic error handling and environment management for variable storage.
This commit is contained in:
39
src/ast/stmt.rs
Normal file
39
src/ast/stmt.rs
Normal file
@@ -0,0 +1,39 @@
|
||||
use crate::ast::expr::Expr;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum Stmt {
|
||||
/// let x = expr;
|
||||
Let {
|
||||
name: String,
|
||||
initializer: Expr,
|
||||
},
|
||||
|
||||
/// 表达式语句:expr;
|
||||
ExprStmt(Expr),
|
||||
|
||||
/// 代码块:{ ... }
|
||||
Block(Vec<Stmt>),
|
||||
|
||||
/// if 语句
|
||||
If {
|
||||
condition: Expr,
|
||||
then_branch: Box<Stmt>,
|
||||
else_branch: Option<Box<Stmt>>,
|
||||
},
|
||||
|
||||
/// while 循环
|
||||
While {
|
||||
condition: Expr,
|
||||
body: Box<Stmt>,
|
||||
},
|
||||
|
||||
/// 函数声明
|
||||
Function {
|
||||
name: String,
|
||||
params: Vec<String>,
|
||||
body: Vec<Stmt>,
|
||||
},
|
||||
|
||||
/// return expr?;
|
||||
Return(Option<Expr>),
|
||||
}
|
||||
Reference in New Issue
Block a user