hmm
This commit is contained in:
parent
0c30f0022d
commit
d7795e52f9
10 changed files with 276 additions and 31 deletions
71
src/code_generation/mod.rs
Normal file
71
src/code_generation/mod.rs
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
pub mod compiler;
|
||||
|
||||
// LLVM Codegen
|
||||
|
||||
|
||||
//--------------------------
|
||||
// Parser
|
||||
//-------------------------
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
use logos::Lexer;
|
||||
|
||||
use crate::tokens::Token;
|
||||
|
||||
/// Defines a primitive expression
|
||||
#[derive(Debug)]
|
||||
pub enum Expr {
|
||||
Binary {
|
||||
op: char,
|
||||
left: Box<Expr>,
|
||||
right: Box<Expr>,
|
||||
},
|
||||
Call {
|
||||
fn_name: String,
|
||||
args: Vec<Expr>,
|
||||
},
|
||||
Conditional {
|
||||
cond: Box<Expr>,
|
||||
consequence: Box<Expr>,
|
||||
alternative: Box<Expr>,
|
||||
},
|
||||
For {
|
||||
var_name: String,
|
||||
start: Box<Expr>,
|
||||
end: Box<Expr>,
|
||||
step: Option<Box<Expr>>,
|
||||
body: Box<Expr>,
|
||||
},
|
||||
Number(f64),
|
||||
Variable(String),
|
||||
VarIn {
|
||||
variables: Vec<(String, Option<Expr>)>,
|
||||
body: Box<Expr>,
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// Defines the prototype (name and parameters) of a function
|
||||
#[derive(Debug)]
|
||||
pub struct Prototype {
|
||||
pub name: String,
|
||||
pub args: Vec<String>,
|
||||
pub is_op: bool,
|
||||
pub prec: usize,
|
||||
}
|
||||
|
||||
/// Defines a user-defined or external function
|
||||
#[derive(Debug)]
|
||||
pub struct Function {
|
||||
pub prototype: Prototype,
|
||||
pub body: Option<Expr>,
|
||||
pub is_anon: bool,
|
||||
}
|
||||
|
||||
pub struct Parser<'a> {
|
||||
tokens: Vec<Token<'a>>,
|
||||
pos: usize,
|
||||
prec: &'a mut HashMap<char, i32>,
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue