Evaluate while loop
This commit is contained in:
parent
dc81d237c5
commit
538f0b18f4
@ -1,6 +1,7 @@
|
||||
extern crate take_mut;
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::collections::VecDeque;
|
||||
use parser::{AST, Statement, Expression, Function};
|
||||
use std::rc::Rc;
|
||||
|
||||
@ -206,8 +207,11 @@ impl<'a> Evaluator<'a> {
|
||||
(Call(name, args), None)
|
||||
}
|
||||
}
|
||||
While(box test, body) => {
|
||||
unimplemented!()
|
||||
While(test, body) => {
|
||||
let mut block = VecDeque::from(body.clone());
|
||||
block.push_back(While(test.clone(), body.clone()));
|
||||
let reduction = Conditional(test, Box::new(Block(block)), None);
|
||||
(reduction, None)
|
||||
}
|
||||
Conditional(box test, then_block, else_block) => {
|
||||
if test.is_reducible() {
|
||||
|
7
while.schala
Normal file
7
while.schala
Normal file
@ -0,0 +1,7 @@
|
||||
|
||||
|
||||
a = 0
|
||||
while a < 10
|
||||
print("hello", a)
|
||||
a = a + 1
|
||||
end
|
Loading…
Reference in New Issue
Block a user