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

37 lines
755 B
Rust
Raw Normal View History

use std::io;
use interpreter::interpret;
use parser::parse;
use symtab::SymTab;
use tokenizer::tokenize;
2025-02-04 16:09:05 +02:00
use type_checker::type_check;
2025-01-24 14:41:23 +02:00
mod ast;
mod interpreter;
2025-01-24 14:41:23 +02:00
mod parser;
mod symtab;
2025-01-18 18:58:14 +02:00
mod token;
mod tokenizer;
2025-02-04 16:09:05 +02:00
mod type_checker;
2025-02-04 14:10:16 +02:00
mod variable;
2025-01-18 18:58:14 +02:00
pub fn compile(code: &str) {
2025-02-04 16:09:05 +02:00
let tokens = tokenize(code);
let ast = parse(&tokens);
type_check(&ast, &mut SymTab::new_type_table());
2025-01-18 18:58:14 +02:00
}
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);
2025-02-04 16:09:05 +02:00
let val = interpret(&ast, &mut SymTab::new_val_table());
println!("{}", val);
}
}
}