Variable binding infrastructure
This commit is contained in:
parent
785c916ece
commit
19fffd5063
23
src/eval.rs
23
src/eval.rs
@ -1,13 +1,32 @@
|
|||||||
|
use std::collections::HashMap;
|
||||||
use parser::{AST, ASTNode, Expression};
|
use parser::{AST, ASTNode, Expression};
|
||||||
|
|
||||||
|
struct Varmap {
|
||||||
|
map: HashMap<String, Expression>
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Varmap {
|
||||||
|
fn new() -> Varmap {
|
||||||
|
Varmap { map: HashMap::new() }
|
||||||
|
}
|
||||||
|
|
||||||
|
fn add_binding(&mut self, var: String, value: Expression) {
|
||||||
|
self.map.insert(var, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn lookup_binding(&mut self, var: String) -> Option<&Expression> {
|
||||||
|
self.map.get(&var)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct Evaluator {
|
pub struct Evaluator {
|
||||||
data: bool,
|
varmap: Varmap
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Evaluator {
|
impl Evaluator {
|
||||||
|
|
||||||
pub fn new() -> Evaluator {
|
pub fn new() -> Evaluator {
|
||||||
Evaluator { data: false }
|
Evaluator { varmap: Varmap::new() }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run(&mut self, ast: AST) -> Vec<String> {
|
pub fn run(&mut self, ast: AST) -> Vec<String> {
|
||||||
|
Loading…
Reference in New Issue
Block a user