mute/src/main.rs

36 lines
736 B
Rust
Raw Normal View History

2023-09-12 11:21:51 +00:00
use std::io::{self, Write};
2023-09-19 14:15:40 +00:00
mod evaluator;
2023-09-13 12:47:24 +00:00
mod lexer;
mod parser;
2023-09-12 11:21:51 +00:00
fn main() {
2023-09-19 14:15:40 +00:00
let env = evaluator::core_environment();
2023-09-12 11:21:51 +00:00
let mut input = String::new();
println!("MAL -- REPL");
loop {
print!("> ");
io::stdout().flush().expect("failed to write to stdout");
let bytes_read = io::stdin()
.read_line(&mut input)
.expect("failed to read from stdin");
if bytes_read == 0 {
break;
}
2023-09-13 12:47:24 +00:00
let tokens = lexer::read(&input).unwrap();
let ast = parser::parse(tokens).unwrap();
2023-09-19 14:15:40 +00:00
let res = evaluator::eval(env.clone(), ast).unwrap();
2023-09-12 11:21:51 +00:00
2023-09-19 12:17:13 +00:00
for expr in res {
println!("{expr}")
}
2023-09-12 11:21:51 +00:00
input.clear();
}
}