Skip to content

Commit

Permalink
implement for statement
Browse files Browse the repository at this point in the history
  • Loading branch information
MenTaLguY committed May 17, 2011
1 parent 187e260 commit 2e4f670
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/razorpit/eval.rb
Expand Up @@ -157,6 +157,16 @@ def evaluate(env)
end
end

Nodes::For.class_eval do
def evaluate(env)
init.evaluate(env) if init
while predicate ? Eval.to_boolean(predicate.evaluate(env)) : true
body.evaluate(env)
incr.evaluate(env) if incr
end
end
end

Nodes::Identifier.class_eval do
def evaluate(env)
env[name]
Expand Down
7 changes: 7 additions & 0 deletions spec/eval_spec.rb
Expand Up @@ -459,6 +459,13 @@ def expr(string)
i;
}).should == 2
end

it "implements for" do
program(%Q{
for (i = 0, j = 0; i < 4; i++) j++;
j;
}).should == 4
end
end


Expand Down

0 comments on commit 2e4f670

Please sign in to comment.