diff options
author | Joe Zhao <ztuowen@gmail.com> | 2014-03-20 13:39:18 +0800 |
---|---|---|
committer | Joe Zhao <ztuowen@gmail.com> | 2014-03-20 13:39:18 +0800 |
commit | a0826ed9f0dcfd9b7c831fa17114818c63898176 (patch) | |
tree | 51e53245a61365f4ba13ea047045b5870b551d85 | |
parent | b5dc5a923ff86163319424affd8cfa6bfc063841 (diff) | |
download | computation-small_step.tar.gz computation-small_step.tar.bz2 computation-small_step.zip |
add whilesmall_step
-rw-r--r-- | simple/simple.rb | 20 |
1 files changed, 20 insertions, 0 deletions
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 |