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:
0264408
2026-02-04 16:42:51 +08:00
commit f86300f3ce
19 changed files with 1484 additions and 0 deletions

39
src/ast/stmt.rs Normal file
View 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>),
}