2022-01-21 17:43:50 -06:00
|
|
|
use std::{fs::read_to_string, env::args, path::Path};
|
|
|
|
|
|
|
|
mod token;
|
|
|
|
mod util;
|
|
|
|
mod lexer;
|
|
|
|
mod parser;
|
2022-01-23 05:49:54 -06:00
|
|
|
mod compiler;
|
2022-01-21 17:43:50 -06:00
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let args = args().nth(1).expect("No input file");
|
|
|
|
|
|
|
|
let src = util::cover_paren(read_to_string(&args).unwrap());
|
|
|
|
let _file_name = Path::new(&args).file_stem().unwrap().to_str().unwrap();
|
|
|
|
|
|
|
|
let tokens = lexer::lexer(&src);
|
|
|
|
if tokens.is_err() {
|
2022-01-22 15:36:13 -06:00
|
|
|
eprintln!("{}", tokens.unwrap_err());
|
|
|
|
return;
|
2022-01-21 17:43:50 -06:00
|
|
|
} else {
|
2022-01-22 15:36:13 -06:00
|
|
|
// for t in tokens.as_ref().unwrap() {
|
|
|
|
// println!("{:?}", t);
|
|
|
|
// }
|
|
|
|
let ast = parser::parse(tokens.unwrap(), &args);
|
|
|
|
if ast.is_err() {
|
|
|
|
eprintln!("{}", ast.as_ref().unwrap_err());
|
|
|
|
return;
|
|
|
|
} else {
|
2022-01-23 05:49:54 -06:00
|
|
|
let c = parser::translate_expr(ast.unwrap());
|
|
|
|
match c {
|
|
|
|
Ok(e) => {
|
|
|
|
println!("{:#?}", e);
|
|
|
|
}
|
|
|
|
Err(e) => {
|
|
|
|
eprintln!("{}", e);
|
|
|
|
}
|
|
|
|
}
|
2022-01-21 17:53:56 -06:00
|
|
|
}
|
2022-01-21 17:43:50 -06:00
|
|
|
}
|
|
|
|
}
|