- Impl. expression only statement (expr;)
- Impl. let binding ("let" ident "=" expr;)
- Impl. assignment (ident "=" expr;)
42 lines
841 B
Rust
42 lines
841 B
Rust
use crate::token::Literal;
|
|
|
|
/// Binary Operator Types. For operations that have two operands
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub enum BinOpType {
|
|
Add,
|
|
Sub,
|
|
|
|
Mul,
|
|
Div,
|
|
Mod
|
|
}
|
|
|
|
/// Unary Operator Types. For operations that have one operand
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub enum UnOpType {
|
|
Neg
|
|
}
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct FnCall {
|
|
pub fn_name: String,
|
|
pub args: Vec<Expr>,
|
|
}
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub enum Expr {
|
|
Literal(Literal),
|
|
// contains variable name
|
|
Variable(String),
|
|
FnCall(FnCall),
|
|
BinOp(BinOpType, Box<Expr>, Box<Expr>),
|
|
UnOp(UnOpType, Box<Expr>),
|
|
}
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub enum Statement {
|
|
Expr(Expr),
|
|
LetBinding(String, Expr),
|
|
Assignment(String, Expr),
|
|
}
|