AkaiLang/src/code_generation/mod.rs
2025-08-05 22:02:39 +02:00

71 lines
1.3 KiB
Rust

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>,
}