2023-09-12 11:21:51 +00:00
|
|
|
use std::io::{self, Write};
|
|
|
|
|
2023-09-13 12:47:24 +00:00
|
|
|
mod lexer;
|
|
|
|
mod parser;
|
|
|
|
|
2023-09-12 11:21:51 +00:00
|
|
|
fn main() {
|
|
|
|
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();
|
|
|
|
let res = eval(ast);
|
2023-09-12 11:21:51 +00:00
|
|
|
|
|
|
|
println!("{res}");
|
|
|
|
|
|
|
|
input.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-13 12:47:24 +00:00
|
|
|
fn eval(input: Vec<parser::Node>) -> String {
|
|
|
|
format!("{input:?}")
|
2023-09-12 11:21:51 +00:00
|
|
|
}
|