40 lines
655 B
Rust
40 lines
655 B
Rust
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>),
|
||
}
|