fixed exit behavior

parent 6ebac1f3
......@@ -16,8 +16,6 @@ mod lexer {
Make, // make
Exit, // exit // TODO: make it interpreter only
Int, // int type
Integer(i64), // litteral integer
Equals, // =
Plus, // +
......@@ -48,7 +46,6 @@ mod lexer {
// native keywords ////////////////////////////////////////////////////
r#"print"# => (Token::Print, text), // `print`
r#"make"# => (Token::Make, text), // `make`
r#"int"# => (Token::Int, text), // `int`
r#"exit"# => (Token::Exit, text), // `exit`
// numbers ////////////////////////////////////////////////////////////
......@@ -226,6 +223,10 @@ mod parser {
span: span!(),
node: Expr_::Div(Box::new(lhs), Box::new(rhs)),
},
Exit => Expr {
span: span!(),
node: Expr_::Exit,
},
atom[x] => x
}
......@@ -279,6 +280,7 @@ mod interp {
val
},
Exit => {
println!("Goodbye!");
::std::process::exit(0);
}
}
......@@ -287,18 +289,15 @@ mod interp {
fn main() {
use std::io::{self, Write};
let mut env // : HashMap<&str, i64>
= HashMap::new();
println!("Welcome to the PAKDRA interpreter.");
println!("Type `exit;` to exit (duh)");
let mut env = HashMap::new();
let mut i: usize = 0;
loop {
i += 1;
print!("{:5} > ", i);
io::stdout().flush().unwrap();
let s: String = read!("{}\n");
if s == "exit;" {
println!("Goodbye!");
break;
}
let lexer = lexer::Lexer::new(&s).inspect(|tok| eprintln!("tok: {:?}", tok));
interp::interp(parser::parse(lexer).unwrap(), &mut env);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment