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
+84
View File
@@ -0,0 +1,84 @@
use crate::ast::stmt::Stmt;
#[derive(Debug, Clone)]
pub enum Expr {
/// 字面量:number / string / bool / nil
Literal(Literal),
/// 变量引用
Variable(String),
/// 赋值表达式:a = b
Assign {
name: String,
value: Box<Expr>,
},
/// 一元运算:!expr / -expr
Unary {
op: UnaryOp,
right: Box<Expr>,
},
/// 二元运算:a + b
Binary {
left: Box<Expr>,
op: BinaryOp,
right: Box<Expr>,
},
/// 逻辑运算:&& ||
Logical {
left: Box<Expr>,
op: LogicalOp,
right: Box<Expr>,
},
/// 函数调用
Call {
callee: Box<Expr>,
arguments: Vec<Expr>,
},
/// 匿名函数(为闭包预留)
Lambda {
params: Vec<String>,
body: Vec<Stmt>,
},
}
#[derive(Debug, Clone)]
pub enum Literal {
Number(f64),
String(String),
Bool(bool),
Nil,
}
#[derive(Debug, Clone, Copy)]
pub enum UnaryOp {
Negate, // -
Not, // !
}
#[derive(Debug, Clone, Copy)]
pub enum BinaryOp {
Add,
Sub,
Mul,
Div,
Greater,
GreaterEqual,
Less,
LessEqual,
Equal,
NotEqual,
}
#[derive(Debug, Clone, Copy)]
pub enum LogicalOp {
And,
Or,
}