From a0826ed9f0dcfd9b7c831fa17114818c63898176 Mon Sep 17 00:00:00 2001 From: Joe Zhao Date: Thu, 20 Mar 2014 13:39:18 +0800 Subject: add while --- simple/simple.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/simple/simple.rb b/simple/simple.rb index a31e001..a045347 100644 --- a/simple/simple.rb +++ b/simple/simple.rb @@ -178,7 +178,27 @@ class Sequence < Struct.new(:first, :second) else reduced_first, reduced_environment = first.reduce(environment) [Sequence.new(reduced_first, second), reduced_environment] + end + end +end + +class While < Struct.new(:condition,:body) + def to_s + "while (#{condition} { #{body} })" + end + + def inspect + "<#{self}>" + end + + def reducible? + true + end + + def reduce(environment) + [If.new(condition,Sequence.new(body,self),DoNothing.new), environment] end +end class Machine < Struct.new(:statement, :environment) def step -- cgit v1.2.3-70-g09d2