-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathast.rs
53 lines (45 loc) · 1014 Bytes
/
ast.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
use crate::lexer::Token;
pub trait Codegen {
fn codegen(&self) {}
}
#[derive(PartialEq, Clone, Debug)]
pub enum ExprAST {
NumberExpr(NumberExprAST),
VariableExpr(VariableExprAST),
BinaryExpr(BinaryExprAST),
CallExpr(CallExprAST),
}
#[derive(PartialEq, Clone, Debug)]
pub struct NumberExprAST {
pub num: f64,
}
#[derive(PartialEq, Clone, Debug)]
pub struct VariableExprAST {
pub name: String,
}
#[derive(PartialEq, Clone, Debug)]
pub struct BinaryExprAST {
pub op: Token,
pub lhs: Box<ExprAST>,
pub rhs: Box<ExprAST>,
}
#[derive(PartialEq, Clone, Debug)]
pub struct CallExprAST {
pub callee: String,
pub args: Vec<ExprAST>,
}
#[derive(PartialEq, Clone, Debug)]
pub struct PrototypeAST {
pub name: String,
pub args: Vec<String>,
}
impl PrototypeAST {
pub fn get_name(&self) -> String {
self.name.clone()
}
}
#[derive(PartialEq, Clone, Debug)]
pub struct FunctionAST {
pub prototype: Box<PrototypeAST>,
pub body: Box<ExprAST>,
}