1
1
Fork 0
mirror of https://github.com/azur1s/bobbylisp.git synced 2024-10-16 02:37:40 -05:00
bobbylisp/blspc/src/main.rs

43 lines
1 KiB
Rust
Raw Normal View History

2022-01-25 16:06:57 -06:00
use std::{fs::{read_to_string, File}, path::Path, io::Write};
2022-01-24 14:08:41 -06:00
use structopt::StructOpt;
mod args;
use args::Args;
2022-01-21 17:43:50 -06:00
mod util;
2022-01-23 15:42:08 -06:00
use util::cover_paren;
2022-01-21 17:43:50 -06:00
mod parser;
2022-01-24 14:08:41 -06:00
use parser::{tokenize, Parser};
2022-01-21 17:43:50 -06:00
2022-01-25 19:45:59 -06:00
mod compiler;
use compiler::compile::Compiler;
2022-01-25 16:06:57 -06:00
2022-01-21 17:43:50 -06:00
fn main() {
2022-01-24 14:08:41 -06:00
let args = Args::from_args();
2022-01-23 15:42:08 -06:00
2022-01-24 14:08:41 -06:00
let src = cover_paren(read_to_string(&args.file).unwrap());
2022-01-25 16:06:57 -06:00
let file_name = Path::new(&args.file).file_stem().unwrap().to_str().unwrap();
2022-01-23 15:42:08 -06:00
2022-01-24 14:08:41 -06:00
let tokens = tokenize(&src);
let mut parser = Parser::new(tokens.clone());
2022-01-23 15:42:08 -06:00
let result = parser.parse();
2022-01-24 14:08:41 -06:00
match args.verbose {
2022-01-25 16:06:57 -06:00
0 => {
let mut file = File::create(format!("{}.bbb", file_name)).unwrap();
2022-01-25 19:31:11 -06:00
let mut compiler = Compiler::new();
for instr in compiler.compile(result.unwrap()).unwrap() {
write!(file, "{}\n", instr).unwrap();
2022-01-25 16:06:57 -06:00
}
},
2022-01-24 14:08:41 -06:00
1 => println!("{:?}", result),
2 | _ => {
println!("Tokens: {:?}", tokens);
println!("Parsed: {:#?}", result);
}
}
2022-01-21 17:43:50 -06:00
}