1
0
Fork 0

Add error handling for parser

This commit is contained in:
Vili Sinervä 2025-02-26 22:31:04 +02:00
parent 9a13d0b9b6
commit 02026c42e0
No known key found for this signature in database
GPG key ID: DF8FEAF54EFAC996
6 changed files with 286 additions and 214 deletions

View file

@ -25,7 +25,7 @@ mod variable;
pub fn compile(code: &str) -> Result<String, Box<dyn Error>> {
let tokens = tokenize(code)?;
let mut ast = parse(&tokens);
let mut ast = parse(&tokens)?;
type_check(&mut ast, &mut SymTab::new_type_table());
let ir = generate_ir(&ast);
let assembly = generate_assembly(&ir);
@ -49,7 +49,7 @@ pub fn start_interpreter() {
for line in lines {
if let Ok(code) = line {
let tokens = tokenize(&code).unwrap();
let ast = parse(&tokens);
let ast = parse(&tokens).unwrap();
let val = interpret(&ast, &mut SymTab::new_val_table());
println!("{}", val);