Beginning of variable lookup

everything is null
This commit is contained in:
greg 2015-07-31 00:27:24 -07:00
parent 6897eb1283
commit 6ddea790c0
2 changed files with 17 additions and 0 deletions

View File

@ -16,6 +16,12 @@ impl Environment {
Environment(ref mut hash_map) => hash_map.insert(name, binding)
};
}
fn lookup_binding(&mut self, name: &String) -> Option<&Box<AST>> {
match *self {
Environment(ref mut hash_map) => hash_map.get(name)
}
}
}
pub fn evaluate(ast: AST, env: Environment) -> String {
@ -26,6 +32,7 @@ pub fn evaluate(ast: AST, env: Environment) -> String {
DoNothing => "".to_string(),
Number(n) => return format!("{}", n),
LangString(s) => return format!("\"{}\"", s),
Null => "null".to_string(),
_ => return "not implemented".to_string()
}
}
@ -34,6 +41,15 @@ fn reduce(evr: EvalResult) -> EvalResult {
let (mut ast, mut env) = evr;
match ast {
Name(name) => {
match env.lookup_binding(&name) {
Some(_) => {
(Null, env)
},
None => (Null, env)
}
},
Statements(stmts) => {
let mut reduced_ast = DoNothing;
let mut reduced_env = env;

View File

@ -6,6 +6,7 @@ use tokenizer::Token::*;
#[derive(Debug)]
pub enum AST {
Null,
Name(String),
LangString(String),
Number(f64),