From 231de69084fcfbd4fbb1d00fc24450777842dc85 Mon Sep 17 00:00:00 2001 From: greg Date: Sun, 24 Jan 2016 22:25:12 -0800 Subject: [PATCH] Added infrastructure for reading files --- src/main.rs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index febceaf..3cb9cc9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -19,13 +19,29 @@ mod eval; fn main() { let args: Vec = std::env::args().collect(); - println!("Schala v 0.02"); if let Some(filename) = args.get(1) { let mut source_file = File::open(&Path::new(filename)).unwrap(); let mut buffer = String::new(); source_file.read_to_string(&mut buffer).unwrap(); - panic!("Not implemented yet"); + + let tokens = match tokenize(&buffer) { + Some(t) => t, + None => { println!("Tokenization error"); return; } + }; + + let ast = match parse(&tokens, &[]) { + Ok(ast) => ast, + Err(err) => { println!("Parse error: {:?}", err); return; } + }; + + let mut evaluator = Evaluator::new(); + let results = evaluator.run(ast); + for result in results.iter() { + println!("{}", result); + } + } else { + println!("Schala v 0.02"); let initial_state = InterpreterState { show_tokens: false, show_parse: false,