Files
aster/src/ast/stmt.rs

40 lines
655 B
Rust
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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>),
}