Hooked up the interpreter
This commit is contained in:
parent
2aa9fb278a
commit
b89e330423
2 changed files with 17 additions and 2 deletions
|
@ -1,6 +1,6 @@
|
|||
use crate::{
|
||||
ast,
|
||||
errors::InterpreterError,
|
||||
errors::{ErrorHandler, InterpreterError},
|
||||
tokens::{Token, TokenType},
|
||||
};
|
||||
|
||||
|
@ -31,6 +31,16 @@ pub trait Interpretable {
|
|||
fn interprete(&self) -> Result<Value, InterpreterError>;
|
||||
}
|
||||
|
||||
/// Evaluate an interpretable, returning its value.
|
||||
pub fn evaluate(err_hdl: &mut ErrorHandler, ast: &dyn Interpretable) -> Option<Value> {
|
||||
match ast.interprete() {
|
||||
Ok(v) => Some(v),
|
||||
Err(e) => {
|
||||
e.report(err_hdl);
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------- *
|
||||
* INTERPRETER FOR EXPRESSION NODES *
|
||||
|
|
|
@ -13,6 +13,7 @@ use std::{
|
|||
|
||||
use ast::AstDumper;
|
||||
use errors::ErrorHandler;
|
||||
use interpreter::evaluate;
|
||||
use parser::Parser;
|
||||
use scanner::Scanner;
|
||||
|
||||
|
@ -31,7 +32,11 @@ fn run(source: String) -> ErrorHandler {
|
|||
match parser.parse(&mut error_handler) {
|
||||
None => (),
|
||||
Some(ast) => {
|
||||
println!("AST generated ! {}", ast.dump())
|
||||
println!("AST generated ! {}", ast.dump());
|
||||
match evaluate(&mut error_handler, &ast) {
|
||||
Some(v) => println!("Final evaluated value: {:?}", v),
|
||||
None => (),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue