1
0
Fork 0

Add first part of IR Generator implementation

This commit is contained in:
Vili Sinervä 2025-02-05 17:16:17 +02:00
parent f059870e81
commit dc50ce64eb
No known key found for this signature in database
GPG key ID: DF8FEAF54EFAC996
5 changed files with 238 additions and 1 deletions

View file

@ -1,6 +1,8 @@
use std::io;
use interpreter::interpret;
use ir::IrInstruction;
use ir_generator::generate_ir;
use parser::parse;
use symtab::SymTab;
use tokenizer::tokenize;
@ -8,6 +10,8 @@ use type_checker::type_check;
mod ast;
mod interpreter;
mod ir;
mod ir_generator;
mod parser;
mod symtab;
mod token;
@ -15,10 +19,20 @@ mod tokenizer;
mod type_checker;
mod variable;
pub fn compile(code: &str) {
pub fn compile(code: &str) -> Vec<IrInstruction> {
let tokens = tokenize(code);
let mut ast = parse(&tokens);
type_check(&mut ast, &mut SymTab::new_type_table());
generate_ir(&ast)
}
pub fn start_compiler() {
let lines = io::stdin().lines();
for line in lines.map_while(Result::ok) {
for instruction in compile(&line) {
println!("{instruction}");
}
}
}
pub fn start_interpreter() {