1
0
Fork 0
This repository has been archived on 2025-03-30. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
compiler-course/src/compiler.rs

36 lines
755 B
Rust

use std::io;
use interpreter::interpret;
use parser::parse;
use symtab::SymTab;
use tokenizer::tokenize;
use type_checker::type_check;
mod ast;
mod interpreter;
mod parser;
mod symtab;
mod token;
mod tokenizer;
mod type_checker;
mod variable;
pub fn compile(code: &str) {
let tokens = tokenize(code);
let ast = parse(&tokens);
type_check(&ast, &mut SymTab::new_type_table());
}
pub fn start_interpreter() {
let lines = io::stdin().lines();
#[allow(clippy::manual_flatten)]
for line in lines {
if let Ok(code) = line {
let tokens = tokenize(&code);
let ast = parse(&tokens);
let val = interpret(&ast, &mut SymTab::new_val_table());
println!("{}", val);
}
}
}