summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Zhao <ztuowen@gmail.com>2014-03-20 13:39:18 +0800
committerJoe Zhao <ztuowen@gmail.com>2014-03-20 13:39:18 +0800
commita0826ed9f0dcfd9b7c831fa17114818c63898176 (patch)
tree51e53245a61365f4ba13ea047045b5870b551d85
parentb5dc5a923ff86163319424affd8cfa6bfc063841 (diff)
downloadcomputation-a0826ed9f0dcfd9b7c831fa17114818c63898176.tar.gz
computation-a0826ed9f0dcfd9b7c831fa17114818c63898176.tar.bz2
computation-a0826ed9f0dcfd9b7c831fa17114818c63898176.zip
add whilesmall_step
-rw-r--r--simple/simple.rb20
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