1
1
Fork 0
mirror of https://github.com/azur1s/bobbylisp.git synced 2024-09-28 13:27:38 +00:00
bobbylisp/blspc/src/main.rs

43 lines
1 KiB
Rust
Raw Normal View History

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