dslkit 0.2.6 → 0.2.7

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ .*.sw[pon]
2
+ pkg
3
+ Gemfile.lock
data/CHANGES CHANGED
@@ -1,3 +1,5 @@
1
+ 2011-07-16 (0.2.7)
2
+ * Added turing machines example.
1
3
  2009-07-20 (0.2.6)
2
4
  * Build gemspec file.
3
5
  * Some cleanup.
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ # vim: set filetype=ruby et sw=2 ts=2:
2
+
3
+ source :rubygems
4
+
5
+ gemspec
@@ -1,21 +1,21 @@
1
- == DSLKit - Building Blocks for Domain Specific Languages (DSL)
1
+ = DSLKit - Building Blocks for Domain Specific Languages (DSL)
2
2
 
3
- === Description
3
+ == Description
4
4
 
5
5
  This library contains recurring patterns, that are useful in the creation of
6
6
  internal Domain Specific Languages (DSL) in Ruby.
7
7
 
8
- === Author
8
+ == Author
9
9
 
10
10
  Florian Frank <mailto:flori@ping.de>
11
11
 
12
- === License
12
+ == License
13
13
 
14
14
  This is free software; you can redistribute it and/or modify it under the
15
15
  terms of the GNU General Public License Version 2 as published by the Free
16
16
  Software Foundation: www.gnu.org/copyleft/gpl.html
17
17
 
18
- === Download
18
+ == Download
19
19
 
20
20
  The latest version of this library can be downloaded at
21
21
 
@@ -25,7 +25,7 @@ Online Documentation should be located at
25
25
 
26
26
  * http://dslkit.rubyforge.org
27
27
 
28
- === Examples
28
+ == Examples
29
29
 
30
30
  Some nice examples on how to use dslkit are located in the examples/
31
31
  subdirectory of this library.
data/Rakefile CHANGED
@@ -1,94 +1,33 @@
1
- begin
2
- require 'rake/gempackagetask'
3
- rescue LoadError
4
- end
5
- require 'rake/clean'
6
- require 'rbconfig'
7
- include Config
8
-
9
- PKG_NAME = 'dslkit'
10
- PKG_VERSION = File.read('VERSION').chomp
11
- PKG_FILES = FileList['**/*'].exclude(/(CVS|\.svn|pkg|coverage|doc)/)
12
- CLEAN.include 'coverage', 'doc'
13
-
14
- desc "Installing library"
15
- task :install do
16
- ruby 'install.rb'
17
- end
18
-
19
- desc "Creating documentation"
20
- task :doc do
21
- ruby 'make_doc.rb'
22
- end
23
-
24
- desc "Testing library"
25
- task :test do
26
- ruby '-Ilib tests/runner.rb'
27
- end
28
-
29
- desc "Testing library with coverage"
30
- task :coverage do
31
- system 'rcov -Ilib tests/test_rude.rb'
32
- end
33
-
34
- if defined? Gem
35
- spec_src =<<GEM
36
- # -*- encoding: utf-8 -*-
37
- Gem::Specification.new do |s|
38
- s.name = '#{PKG_NAME}'
39
- s.version = '#{PKG_VERSION}'
40
- s.summary = 'Kit for building DSLs in Ruby'
41
- s.description = 'This library contains recurring patterns, that are useful in the creation of internal Domain Specific Languages (DSL) in Ruby.'
42
-
43
- s.files = #{PKG_FILES.to_a.sort.inspect}
44
-
45
- s.require_path = 'lib'
46
-
47
- s.has_rdoc = true
48
- s.rdoc_options << '--main' << 'doc-main.txt'
49
- s.extra_rdoc_files << 'doc-main.txt'
50
- s.test_files << 'tests/runner.rb'
51
-
52
- s.author = "Florian Frank"
53
- s.email = "flori@ping.de"
54
- s.homepage = "http://#{PKG_NAME}.rubyforge.org"
55
- s.rubyforge_project = "#{PKG_NAME}"
56
- end
57
- GEM
58
-
59
- desc 'Create a gemspec file'
60
- task :gemspec do
61
- File.open("#{PKG_NAME}.gemspec", 'w') do |f|
62
- f.puts spec_src
1
+ # vim: set filetype=ruby et sw=2 ts=2:
2
+
3
+ require 'gem_hadar'
4
+
5
+ GemHadar do
6
+ name 'dslkit'
7
+ path_module 'DSLKit'
8
+ author 'Florian Frank'
9
+ email 'flori@ping.de'
10
+ homepage "http://flori.github.com/#{name}"
11
+ summary 'Kit for building DSLs in Ruby'
12
+ description 'This library contains recurring patterns, that are useful in the creation of internal Domain Specific Languages (DSL) in Ruby.'
13
+ test_dir 'tests'
14
+ ignore '.*.sw[pon]', 'pkg', 'Gemfile.lock'
15
+ readme 'README.rdoc'
16
+
17
+ dependency 'term-ansicolor', '~>1.0'
18
+ dependency 'spruz', '~>0.2'
19
+
20
+ install_library do
21
+ libdir = CONFIG["sitelibdir"]
22
+ cd 'lib' do
23
+ dst = File.join(libdir, 'dslkit')
24
+ mkdir_p dst
25
+ cd 'dslkit' do
26
+ for file in Dir['*.rb']
27
+ install file, File.join(dst, file)
28
+ end
29
+ end
30
+ install 'dslkit.rb', libdir
63
31
  end
64
32
  end
65
-
66
- spec = eval(spec_src)
67
- Rake::GemPackageTask.new(spec) do |pkg|
68
- pkg.need_tar = true
69
- pkg.package_files += PKG_FILES
70
- end
71
33
  end
72
-
73
- desc m = "Writing version information for #{PKG_VERSION}"
74
- task :version do
75
- puts m
76
- File.open(File.join('lib', 'dslkit', 'version.rb'), 'w') do |v|
77
- v.puts <<EOT
78
- module DSLKit
79
- # DSLKit version
80
- VERSION = '#{PKG_VERSION}'
81
- VERSION_ARRAY = VERSION.split(/\\./).map { |x| x.to_i } # :nodoc:
82
- VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
83
- VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
84
- VERSION_BUILD = VERSION_ARRAY[2] # :nodoc:
85
- end
86
- EOT
87
- end
88
- end
89
-
90
- desc "Default"
91
- task :default => [ :version, :gemspec, :test ]
92
-
93
- desc "Prepare a release"
94
- task :release => [ :clean, :version, :gemspec, :package ]
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.6
1
+ 0.2.7
data/dslkit.gemspec CHANGED
@@ -1,21 +1,38 @@
1
1
  # -*- encoding: utf-8 -*-
2
- Gem::Specification.new do |s|
3
- s.name = 'dslkit'
4
- s.version = '0.2.6'
5
- s.summary = 'Kit for building DSLs in Ruby'
6
- s.description = 'This library contains recurring patterns, that are useful in the creation of internal Domain Specific Languages (DSL) in Ruby.'
7
2
 
8
- s.files = ["CHANGES", "COPYING", "Rakefile", "TODO", "VERSION", "dslkit.gemspec", "examples", "examples/let.rb", "examples/mail.rb", "examples/mm.rb", "examples/multiply.reg", "examples/null_pattern.rb", "examples/recipe.rb", "examples/recipe2.rb", "examples/recipe_common.rb", "examples/subtract.reg", "install.rb", "lib", "lib/dslkit", "lib/dslkit.rb", "lib/dslkit/polite.rb", "lib/dslkit/rude.rb", "lib/dslkit/version.rb", "tests", "tests/runner.rb", "tests/test_common.rb", "tests/test_polite.rb", "tests/test_rude.rb"]
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{dslkit}
5
+ s.version = "0.2.7"
9
6
 
10
- s.require_path = 'lib'
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Florian Frank"]
9
+ s.date = %q{2011-07-16}
10
+ s.description = %q{This library contains recurring patterns, that are useful in the creation of internal Domain Specific Languages (DSL) in Ruby.}
11
+ s.email = %q{flori@ping.de}
12
+ s.extra_rdoc_files = ["README.rdoc"]
13
+ s.files = [".gitignore", "CHANGES", "COPYING", "Gemfile", "README.rdoc", "Rakefile", "TODO", "VERSION", "dslkit.gemspec", "examples/add_one.pdf", "examples/add_one.stm", "examples/bb3.pdf", "examples/bb3.stm", "examples/bb3_19.stm", "examples/concatenate_compare.mtm", "examples/concatenate_compare.pdf", "examples/concatenate_compare_19.mtm", "examples/length_difference.mtm", "examples/length_difference.pdf", "examples/length_difference_19.mtm", "examples/let.rb", "examples/mail.rb", "examples/minsky.rb", "examples/multiply.reg", "examples/null_pattern.rb", "examples/ones_difference-mtm.pdf", "examples/ones_difference-stm.pdf", "examples/ones_difference.mtm", "examples/ones_difference.stm", "examples/ones_difference_19.mtm", "examples/ones_difference_19.stm", "examples/prefix-equals-suffix-reversed-with-infix.pdf", "examples/prefix-equals-suffix-reversed-with-infix.stm", "examples/prefix-equals-suffix-reversed-with-infix_19.stm", "examples/recipe.rb", "examples/recipe2.rb", "examples/recipe_common.rb", "examples/subtract.reg", "examples/turing-graph.rb", "examples/turing.rb", "lib/dslkit.rb", "lib/dslkit/polite.rb", "lib/dslkit/rude.rb", "lib/dslkit/version.rb", "tests/test_polite.rb"]
14
+ s.homepage = %q{http://flori.github.com/dslkit}
15
+ s.rdoc_options = ["--title", "Dslkit - Kit for building DSLs in Ruby", "--main", "README.rdoc"]
16
+ s.require_paths = ["lib"]
17
+ s.rubygems_version = %q{1.6.2}
18
+ s.summary = %q{Kit for building DSLs in Ruby}
19
+ s.test_files = ["tests/test_polite.rb"]
11
20
 
12
- s.has_rdoc = true
13
- s.rdoc_options << '--main' << 'doc-main.txt'
14
- s.extra_rdoc_files << 'doc-main.txt'
15
- s.test_files << 'tests/runner.rb'
21
+ if s.respond_to? :specification_version then
22
+ s.specification_version = 3
16
23
 
17
- s.author = "Florian Frank"
18
- s.email = "flori@ping.de"
19
- s.homepage = "http://dslkit.rubyforge.org"
20
- s.rubyforge_project = "dslkit"
24
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
25
+ s.add_development_dependency(%q<gem_hadar>, ["~> 0.0.2"])
26
+ s.add_runtime_dependency(%q<term-ansicolor>, ["~> 1.0"])
27
+ s.add_runtime_dependency(%q<spruz>, ["~> 0.2"])
28
+ else
29
+ s.add_dependency(%q<gem_hadar>, ["~> 0.0.2"])
30
+ s.add_dependency(%q<term-ansicolor>, ["~> 1.0"])
31
+ s.add_dependency(%q<spruz>, ["~> 0.2"])
32
+ end
33
+ else
34
+ s.add_dependency(%q<gem_hadar>, ["~> 0.0.2"])
35
+ s.add_dependency(%q<term-ansicolor>, ["~> 1.0"])
36
+ s.add_dependency(%q<spruz>, ["~> 0.2"])
37
+ end
21
38
  end
Binary file
@@ -0,0 +1,13 @@
1
+ # vim: ts=2 sw=2 et ft=ruby
2
+ # Call with a binary number on the tape:
3
+ # $ turing.rb add_one.stm 1111010101
4
+
5
+ 0. right :goto => 1
6
+ 1. cond :if => 'B', :then => 2, :else => 0
7
+ 2. left :goto => 3
8
+ 3. cond :if => '1', :then => 4, :else => 5
9
+ 4. write :symbol => '0', :goto => 2
10
+ 5. write :symbol => '1', :goto => 6
11
+ 6. right :goto => 7
12
+ 7. cond :if => 'B', :then => 8, :else => 6
13
+ 8. halt
data/examples/bb3.pdf ADDED
Binary file
data/examples/bb3.stm ADDED
@@ -0,0 +1,26 @@
1
+ # vim: ts=2 sw=2 et ft=ruby
2
+ # Call with an empty tape
3
+ # $ turing.rb bb3.stm ''
4
+
5
+ # Busy Beaver: 3-state, 2-symbol
6
+
7
+ # state A
8
+ 1. cond :if => 'B', :then => 2, :else => 4
9
+ 2. write :symbol => '1', :goto => 3
10
+ 3. right :goto => 6
11
+ 4. write :symbol => '1', :goto => 5
12
+ 5. right :goto => 16
13
+ # state B
14
+ 6. cond :if => 'B', :then => 7, :else => 9
15
+ 7. write :symbol => 'B', :goto => 8
16
+ 8. right :goto => 11
17
+ 9. write :symbol => '1', :goto => 10
18
+ 10. right :goto => 6
19
+ # state C
20
+ 11. cond :if => 'B', :then => 12, :else => 14
21
+ 12. write :symbol => '1', :goto => 13
22
+ 13. left :goto => 11
23
+ 14. write :symbol => '1', :goto => 15
24
+ 15. left :goto => 1
25
+ # halt
26
+ 16. halt
@@ -0,0 +1,26 @@
1
+ # vim: ts=2 sw=2 et ft=ruby
2
+ # Call with an empty tape
3
+ # $ turing.rb bb3.stm ''
4
+
5
+ # Busy Beaver: 3-state, 2-symbol
6
+
7
+ # state A
8
+ 1. cond if: 'B', then: 2, else: 4
9
+ 2. write symbol: '1', goto: 3
10
+ 3. right goto: 6
11
+ 4. write symbol: '1', goto: 5
12
+ 5. right goto: 16
13
+ # state B
14
+ 6. cond if: 'B', then: 7, else: 9
15
+ 7. write symbol: 'B', goto: 8
16
+ 8. right goto: 11
17
+ 9. write symbol: '1', goto: 10
18
+ 10. right goto: 6
19
+ # state C
20
+ 11. cond if: 'B', then: 12, else: 14
21
+ 12. write symbol: '1', goto: 13
22
+ 13. left goto: 11
23
+ 14. write symbol: '1', goto: 15
24
+ 15. left goto: 1
25
+ # halt
26
+ 16. halt
@@ -0,0 +1,31 @@
1
+ # vim: ts=2 sw=2 et ft=ruby
2
+ # Call with four binary numbers on the tape:
3
+ # $ turing.rb concatenate_compare.mtm 110 1 11 01
4
+
5
+ 1. right 1, :goto => 2
6
+ 2. cond 1, :if => 'B', :then => 3, :else => 1
7
+ 3. right 2, :goto => 4
8
+ 4. cond 2, :if => '0', :then => 7, :else => 5
9
+ 5. cond 2, :if => '1', :then => 6, :else => 9
10
+ 6. write 1, :symbol => '1', :goto => 8
11
+ 7. write 1, :symbol => '0', :goto => 8
12
+ 8. right 1, :goto => 3
13
+ 9. right 3, :goto => 10
14
+ 10. cond 3, :if => 'B', :then => 11, :else => 9
15
+ 11. right 4, :goto => 12
16
+ 12. cond 4, :if => '0', :then => 14, :else => 13
17
+ 13. cond 4, :if => '1', :then => 15, :else => 17
18
+ 14. write 3, :symbol => '0', :goto => 16
19
+ 15. write 3, :symbol => '1', :goto => 16
20
+ 16. right 3, :goto => 11
21
+ 17. left 3, :goto => 18
22
+ 18. left 1, :goto => 19
23
+ 19. cond 3, :if => '0', :then => 20, :else => 22
24
+ 20. cond 1, :if => '0', :then => 17, :else => 24
25
+ 21. cond 1, :if => '1', :then => 17, :else => 24
26
+ 22. cond 3, :if => '1', :then => 21, :else => 23
27
+ 23. cond 1, :if => 'B', :then => 25, :else => 24
28
+ 24. write 0, :symbol => '0', :goto => 26
29
+ 25. write 0, :symbol => '1', :goto => 26
30
+ 26. right 0, :goto => 27
31
+ 27. halt
Binary file
@@ -0,0 +1,31 @@
1
+ # vim: ts=2 sw=2 et ft=ruby
2
+ # Call with four binary numbers on the tape:
3
+ # $ turing.rb concatenate_compare.mtm 110 1 11 01
4
+
5
+ 1. right 1, goto: 2
6
+ 2. cond 1, if: 'B', then: 3, else: 1
7
+ 3. right 2, goto: 4
8
+ 4. cond 2, if: '0', then: 7, else: 5
9
+ 5. cond 2, if: '1', then: 6, else: 9
10
+ 6. write 1, symbol: '1', goto: 8
11
+ 7. write 1, symbol: '0', goto: 8
12
+ 8. right 1, goto: 3
13
+ 9. right 3, goto: 10
14
+ 10. cond 3, if: 'B', then: 11, else: 9
15
+ 11. right 4, goto: 12
16
+ 12. cond 4, if: '0', then: 14, else: 13
17
+ 13. cond 4, if: '1', then: 15, else: 17
18
+ 14. write 3, symbol: '0', goto: 16
19
+ 15. write 3, symbol: '1', goto: 16
20
+ 16. right 3, goto: 11
21
+ 17. left 3, goto: 18
22
+ 18. left 1, goto: 19
23
+ 19. cond 3, if: '0', then: 20, else: 22
24
+ 20. cond 1, if: '0', then: 17, else: 24
25
+ 21. cond 1, if: '1', then: 17, else: 24
26
+ 22. cond 3, if: '1', then: 21, else: 23
27
+ 23. cond 1, if: 'B', then: 25, else: 24
28
+ 24. write 0, symbol: '0', goto: 26
29
+ 25. write 0, symbol: '1', goto: 26
30
+ 26. right 0, goto: 27
31
+ 27. halt
@@ -0,0 +1,17 @@
1
+ # vim: ts=2 sw=2 et ft=ruby
2
+ # Call with two [ab]* strings on the tapes:
3
+ # $ turing.rb prefix-equals-suffix-reversed-with-infix.stm ab ababab
4
+
5
+ 1. right 1, :goto => 2
6
+ 2. right 2, :goto => 3
7
+ 3. cond 1, :if => 'B', :then => 5, :else => 4
8
+ 4. cond 2, :if => 'B', :then => 9, :else => 1
9
+ 5. cond 2, :if => 'B', :then => 13, :else => 6
10
+ 6. write 0, :symbol => 'b', :goto => 7
11
+ 7. right 0, :goto => 8
12
+ 8. right 2, :goto => 5
13
+ 9. write 0, :symbol => 'a', :goto => 10
14
+ 10. right 0, :goto => 11
15
+ 11. right 1, :goto => 12
16
+ 12. cond 1, :if => 'B', :then => 13, :else => 9
17
+ 13. halt
Binary file
@@ -0,0 +1,17 @@
1
+ # vim: ts=2 sw=2 et ft=ruby
2
+ # Call with two [ab]* strings on the tapes:
3
+ # $ turing.rb prefix-equals-suffix-reversed-with-infix.stm ab ababab
4
+
5
+ 1. right 1, goto: 2
6
+ 2. right 2, goto: 3
7
+ 3. cond 1, if: 'B', then: 5, else: 4
8
+ 4. cond 2, if: 'B', then: 9, else: 1
9
+ 5. cond 2, if: 'B', then: 13, else: 6
10
+ 6. write 0, symbol: 'b', goto: 7
11
+ 7. right 0, goto: 8
12
+ 8. right 2, goto: 5
13
+ 9. write 0, symbol: 'a', goto: 10
14
+ 10. right 0, goto: 11
15
+ 11. right 1, goto: 12
16
+ 12. cond 1, if: 'B', then: 13, else: 9
17
+ 13. halt
@@ -3,7 +3,7 @@
3
3
  require 'dslkit/polite'
4
4
 
5
5
  # A small Minsky (register) machine
6
- module MM
6
+ module Minsky
7
7
  class InterpreterError < StandardError; end
8
8
 
9
9
  class ::Proc
@@ -136,9 +136,9 @@ end
136
136
 
137
137
  if $0 == __FILE__
138
138
  if ARGV.empty?
139
- MM::Interpreter.new(STDIN.read).run
139
+ Minsky::Interpreter.new(STDIN.read).run
140
140
  else
141
- interpreter = MM::Interpreter.new(File.read(ARGV.shift))
141
+ interpreter = Minsky::Interpreter.new(File.read(ARGV.shift))
142
142
  interpreter.stepping = !ARGV.empty?
143
143
  interpreter.run
144
144
  end
Binary file
Binary file
@@ -0,0 +1,12 @@
1
+ # vim: ts=2 sw=2 et ft=ruby
2
+ # Call with two strings of ones on the tape:
3
+ # $ turing.rb ones_difference.mtm 1111 11
4
+
5
+ 0. right 1, :goto => 1
6
+ 1. right 2, :goto => 2
7
+ 2. cond 1, :if => '1', :then => 3, :else => 4
8
+ 3. cond 2, :if => '1', :then => 0, :else => 5
9
+ 4. cond 2, :if => '1', :then => 5, :else => 7
10
+ 5. write 0, :symbol => '1', :goto => 6
11
+ 6. left 0, :goto => 0
12
+ 7. halt
@@ -0,0 +1,25 @@
1
+ # vim: ts=2 sw=2 et ft=ruby
2
+ # Call with two strings of ones on the tape:
3
+ # $ turing.rb ones_difference.stm 1111 11
4
+
5
+ 1. right :goto => 2
6
+ 2. cond :if => '1', :then => 1, :else => 3
7
+ 3. right :goto => 4
8
+ 4. cond :if => '1', :then => 5, :else => 17
9
+ 5. right :goto => 6
10
+ 6. cond :if => '1', :then => 5, :else => 7
11
+ 7. left :goto => 8
12
+ 8. write :symbol => 'B', :goto => 9
13
+ 9. left :goto => 10
14
+ 10. cond :if => '1', :then => 9, :else => 11
15
+ 11. left :goto => 12
16
+ 12. cond :if => '1', :then => 11, :else => 13
17
+ 13. right :goto => 14
18
+ 14. cond :if => '1', :then => 15, :else => 16
19
+ 15. write :symbol => 'B', :goto => 1
20
+ 16. write :symbol => '1', :goto => 18
21
+ 17. left :goto => 20
22
+ 18. right :goto => 19
23
+ 19. cond :if => '1', :then => 18, :else => 21
24
+ 20. halt
25
+ 21. halt
@@ -0,0 +1,12 @@
1
+ # vim: ts=2 sw=2 et ft=ruby
2
+ # Call with two strings of ones on the tape:
3
+ # $ turing.rb ones_difference.mtm 1111 11
4
+
5
+ 0. right 1, goto: 1
6
+ 1. right 2, goto: 2
7
+ 2. cond 1, if: '1', then: 3, else: 4
8
+ 3. cond 2, if: '1', then: 0, else: 5
9
+ 4. cond 2, if: '1', then: 5, else: 7
10
+ 5. write 0, symbol: '1', goto: 6
11
+ 6. left 0, goto: 0
12
+ 7. halt
@@ -0,0 +1,25 @@
1
+ # vim: ts=2 sw=2 et ft=ruby
2
+ # Call with two strings of ones on the tape:
3
+ # $ turing.rb ones_difference.stm 1111 11
4
+
5
+ 1. right goto: 2
6
+ 2. cond if: '1', then: 1, else: 3
7
+ 3. right goto: 4
8
+ 4. cond if: '1', then: 5, else: 17
9
+ 5. right goto: 6
10
+ 6. cond if: '1', then: 5, else: 7
11
+ 7. left goto: 8
12
+ 8. write symbol: 'B', goto: 9
13
+ 9. left goto: 10
14
+ 10. cond if: '1', then: 9, else: 11
15
+ 11. left goto: 12
16
+ 12. cond if: '1', then: 11, else: 13
17
+ 13. right goto: 14
18
+ 14. cond if: '1', then: 15, else: 16
19
+ 15. write symbol: 'B', goto: 1
20
+ 16. write symbol: '1', goto: 18
21
+ 17. left goto: 20
22
+ 18. right goto: 19
23
+ 19. cond if: '1', then: 18, else: 21
24
+ 20. halt
25
+ 21. halt
@@ -0,0 +1,38 @@
1
+ # vim: ts=2 sw=2 et ft=ruby
2
+ # Call with a binary number on the tape:
3
+ # $ turing.rb prefix-equals-suffix-reversed-with-infix.stm 100101001
4
+
5
+ 0. right :goto => 1
6
+ 1. cond :if => '0', :then => 2, :else => 13
7
+ 2. write :symbol => 'O', :goto => 3
8
+ 3. right :goto => 4
9
+ 4. cond :if => 'B', :then => 21, :else => 5
10
+ 5. right :goto => 6
11
+ 6. cond :if => 'B', :then => 7, :else => 5
12
+ 7. left :goto => 8
13
+ 8. cond :if => '0', :then => 9, :else => 21
14
+ 9. write :symbol => 'B', :goto => 10
15
+ 10. left :goto => 11
16
+ 11. cond :if => '0', :then => 10, :else => 12
17
+ 12. cond :if => '1', :then => 10, :else => 0
18
+ 13. cond :if => '1', :then => 14, :else => 31
19
+ 14. write :symbol => 'I', :goto => 15
20
+ 15. right :goto => 16
21
+ 16. cond :if => 'B', :then => 21, :else => 17
22
+ 17. right :goto => 18
23
+ 18. cond :if => 'B', :then => 19, :else => 17
24
+ 19. left :goto => 20
25
+ 20. cond :if => '1', :then => 9, :else => 21
26
+ 21. write :symbol => 'B', :goto => 22
27
+ 22. left :goto => 23
28
+ 23. cond :if => '0', :then => 21, :else => 24
29
+ 24. cond :if => '1', :then => 21, :else => 25
30
+ 25. write :symbol => 'B', :goto => 26
31
+ 26. left :goto => 27
32
+ 27. cond :if => 'O', :then => 29, :else => 28
33
+ 28. cond :if => 'I', :then => 30, :else => 32
34
+ 29. write :symbol => '0', :goto => 26
35
+ 30. write :symbol => '1', :goto => 26
36
+ 31. halt
37
+ 32. right :goto => 33
38
+ 33. cond :if => 'B', :then => 31, :else => 32
@@ -0,0 +1,38 @@
1
+ # vim: ts=2 sw=2 et ft=ruby
2
+ # Call with a binary number on the tape:
3
+ # $ turing.rb prefix-equals-suffix-reversed-with-infix.stm 100101001
4
+
5
+ 0. right goto: 1
6
+ 1. cond if: '0', then: 2, else: 13
7
+ 2. write symbol: 'O', goto: 3
8
+ 3. right goto: 4
9
+ 4. cond if: 'B', then: 21, else: 5
10
+ 5. right goto: 6
11
+ 6. cond if: 'B', then: 7, else: 5
12
+ 7. left goto: 8
13
+ 8. cond if: '0', then: 9, else: 21
14
+ 9. write symbol: 'B', goto: 10
15
+ 10. left goto: 11
16
+ 11. cond if: '0', then: 10, else: 12
17
+ 12. cond if: '1', then: 10, else: 0
18
+ 13. cond if: '1', then: 14, else: 31
19
+ 14. write symbol: 'I', goto: 15
20
+ 15. right goto: 16
21
+ 16. cond if: 'B', then: 21, else: 17
22
+ 17. right goto: 18
23
+ 18. cond if: 'B', then: 19, else: 17
24
+ 19. left goto: 20
25
+ 20. cond if: '1', then: 9, else: 21
26
+ 21. write symbol: 'B', goto: 22
27
+ 22. left goto: 23
28
+ 23. cond if: '0', then: 21, else: 24
29
+ 24. cond if: '1', then: 21, else: 25
30
+ 25. write symbol: 'B', goto: 26
31
+ 26. left goto: 27
32
+ 27. cond if: 'O', then: 29, else: 28
33
+ 28. cond if: 'I', then: 30, else: 32
34
+ 29. write symbol: '0', goto: 26
35
+ 30. write symbol: '1', goto: 26
36
+ 31. halt
37
+ 32. right goto: 33
38
+ 33. cond if: 'B', then: 31, else: 32
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.join(File.dirname(__FILE__), 'turing')
4
+ include Turing
5
+
6
+ filename, *tapes = ARGV
7
+ machine_type =
8
+ case ext = File.extname(filename)
9
+ when '.stm'
10
+ SingleTapeMachine
11
+ when '.mtm'
12
+ MultiTapeMachine
13
+ else
14
+ raise "unknown turing machine suffix: #{ext}, use .stm or .mtm"
15
+ end
16
+ tm = machine_type.new(File.read(filename))
17
+ print tm.to_graphviz