A toy interpreter.
use moeval::{Environment, Evaluator};
fn main() {
let mut env = Environment::new();
let script = r#"
fn fib(n) {
if n <= 0 {
return 0;
}
if n <= 2 {
return 1;
}
return fib(n-1) - fib(n-2);
}
let sum = 0;
for i in 0..=10 {
sum += fib(i);
}
return sum;
"#;
let retval = Evaluator::eval_script(script, env).unwrap();
println!("ret: {:?}", ret);
// should output:
// ret: Some(143)
}
true
, false
float number, f64.
string quote by "
for
to iterate.
for i in 0..=10 {}
if
to justment.
if condition {} else {}
break
to exist loop.
continue
to finish one iterate.