schala/src/main.rs

50 lines
1.1 KiB
Rust
Raw Normal View History

2015-07-16 02:55:03 -07:00
use std::io;
use std::io::Write;
use std::io::BufRead;
2015-07-22 02:26:46 -07:00
2015-07-22 03:12:01 -07:00
use tokenizer::tokenize;
use parser::{parse, ParseResult};
2015-07-22 03:02:55 -07:00
mod tokenizer;
2015-07-22 03:12:01 -07:00
mod parser;
2015-07-22 02:26:46 -07:00
2015-07-16 02:55:03 -07:00
2015-07-16 01:40:37 -07:00
fn main() {
2015-07-16 02:55:03 -07:00
println!("Unnamed language 0.01");
repl();
}
fn repl() {
2015-07-19 16:53:37 -07:00
let stdin = io::stdin();
2015-07-16 02:55:03 -07:00
let mut stdout = io::stdout();
let mut buf = String::with_capacity(20);
loop {
print!(">> ");
stdout.flush().ok();
let line = stdin.lock().read_line(&mut buf);
match line {
2015-07-19 16:53:37 -07:00
Ok(_) => {
2015-07-19 17:11:22 -07:00
if buf.is_empty() {
break;
}
2015-07-18 14:50:26 -07:00
let tokens = tokenize(&buf);
2015-07-19 00:12:27 -07:00
buf.clear();
2015-07-18 14:50:26 -07:00
println!("Tokens: {:?}", tokens);
2015-07-20 01:46:02 -07:00
match parse(tokens) {
ParseResult::Ok(ast) => println!("AST: {:?}", ast),
ParseResult::Err(err) => println!("Error: {}", err)
2015-07-20 01:46:02 -07:00
}
2015-07-18 15:00:18 -07:00
2015-07-20 01:46:02 -07:00
/*
2015-07-18 15:00:18 -07:00
let eval = evaluate(&ast);
println!("{}", eval);
2015-07-20 01:46:02 -07:00
*/
2015-07-16 02:55:03 -07:00
},
Err(err) => {
println!("Error: {}", err);
}
}
}
}