bfrb 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +9 -4
- data/VERSION +1 -1
- data/bfrb.gemspec +2 -2
- data/bin/bfrb +32 -27
- data/lib/bfrb.rb +11 -3
- metadata +11 -11
data/README.rdoc
CHANGED
@@ -12,28 +12,33 @@ To install bfrb:
|
|
12
12
|
|
13
13
|
Once bfrb is installed, you can use it to interpret your brainfuck code.
|
14
14
|
|
15
|
-
First, you can pass brainfuck code directly into it,
|
15
|
+
First, you can pass brainfuck code directly into it, using the -c parameter:
|
16
16
|
|
17
|
-
% bfrb ",[.,]"
|
17
|
+
% bfrb -c ",[.,]"
|
18
18
|
|
19
19
|
Or, you can specify a file with the -f parameter:
|
20
20
|
|
21
21
|
% bfrb -f test.bf
|
22
22
|
|
23
|
-
You can also start an interactive interpreter by running bfrb without any parameters
|
23
|
+
You can also start an interactive interpreter by running bfrb without any parameters:
|
24
24
|
|
25
25
|
% bfrb
|
26
26
|
|
27
|
+
The list of options is viewable with the -h parameter:
|
28
|
+
|
29
|
+
% bfrb -h
|
30
|
+
|
27
31
|
Just in case you feel the need to use another language internally in a Ruby program, I guess you can:
|
28
32
|
|
29
33
|
require 'rubygems'
|
30
34
|
require 'bfrb'
|
31
35
|
|
32
|
-
bf = BfRb::
|
36
|
+
bf = BfRb::Interpreter.new
|
33
37
|
bf.run ",[.,]"
|
34
38
|
|
35
39
|
== History
|
36
40
|
|
41
|
+
* 0.1.5 - Modified to use OptionParser for command line parameters, 'help' command to REPL
|
37
42
|
* 0.1.4 - Added a little more documentation, efficiency fixes and Ctrl-X to exit a program
|
38
43
|
* 0.1.3 - Unmatched brace checks
|
39
44
|
* 0.1.2 - Added unit tests
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.5
|
data/bfrb.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{bfrb}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.5"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Chris ONeal"]
|
12
|
-
s.date = %q{2011-06-
|
12
|
+
s.date = %q{2011-06-10}
|
13
13
|
s.default_executable = %q{bfrb}
|
14
14
|
s.description = %q{bfrb is a brainfuck interpreter written in Ruby.}
|
15
15
|
s.email = %q{ctoneal@gmail.com}
|
data/bin/bfrb
CHANGED
@@ -1,35 +1,40 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
2
|
+
require 'optparse'
|
3
3
|
require File.expand_path(File.join(File.dirname(__FILE__), "..", "lib", "bfrb.rb"))
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
5
|
+
options = { :mode => :repl }
|
6
|
+
op = OptionParser.new do |x|
|
7
|
+
x.banner = "bfrb <options>"
|
8
|
+
x.separator "\nUsing no options will start the interactive interpreter."
|
9
|
+
x.on("-f <file_path>", String, "Open a given file") do |f|
|
10
|
+
options[:mode] = :file
|
11
|
+
options[:file] = f
|
12
|
+
end
|
13
|
+
x.on("-c <code>", String, "Perform the given code") do |c|
|
14
|
+
options[:mode] = :code
|
15
|
+
options[:code] = c
|
16
|
+
end
|
17
|
+
x.on("-h", "Show this message") do
|
18
|
+
puts op
|
19
|
+
exit
|
20
|
+
end
|
21
|
+
end
|
22
|
+
begin
|
23
|
+
op.parse!(ARGV)
|
24
|
+
rescue
|
25
|
+
puts "Could not parse command line arguments."
|
26
|
+
exit
|
11
27
|
end
|
12
28
|
|
13
29
|
bfrb = BfRb::Base.new
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
puts "Starting interactive evaluation"
|
30
|
+
case options[:mode]
|
31
|
+
when :repl
|
32
|
+
puts "Starting interactive interpreter..."
|
18
33
|
bfrb.repl
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
puts "Attempting to run file #{ARGV[1]}"
|
26
|
-
bfrb.load_file(ARGV[1])
|
27
|
-
else
|
28
|
-
puts "Invalid arguments"
|
29
|
-
usage
|
30
|
-
end
|
31
|
-
else
|
32
|
-
puts "Interpreting code"
|
33
|
-
bfrb.run(ARGV[0])
|
34
|
-
end
|
34
|
+
when :file
|
35
|
+
puts "Running file..."
|
36
|
+
bfrb.load_file(options[:file])
|
37
|
+
when :code
|
38
|
+
puts "Interpreting code..."
|
39
|
+
bfrb.run(options[:code])
|
35
40
|
end
|
data/lib/bfrb.rb
CHANGED
@@ -22,14 +22,14 @@ module BfRb
|
|
22
22
|
|
23
23
|
# interactive read-evaluate-print loop
|
24
24
|
def repl
|
25
|
-
puts "
|
26
|
-
puts "'mem' displays the value in the current cell of memory"
|
27
|
-
puts "'clear' clears everything from memory"
|
25
|
+
puts "For interpreter commands, type 'help'"
|
28
26
|
while true
|
29
27
|
puts ""
|
30
28
|
print "bfrb> "
|
31
29
|
input = gets.chomp
|
32
30
|
case input
|
31
|
+
when "help"
|
32
|
+
repl_help
|
33
33
|
when "exit", 24.chr
|
34
34
|
puts "Exiting"
|
35
35
|
break
|
@@ -42,5 +42,13 @@ module BfRb
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
end
|
45
|
+
|
46
|
+
# prints out a help message
|
47
|
+
def repl_help
|
48
|
+
puts "'exit' or Ctrl-X leaves the REPL"
|
49
|
+
puts "'mem' displays the value in the current cell of memory"
|
50
|
+
puts "'clear' clears everything from memory"
|
51
|
+
puts "'help' displays this message"
|
52
|
+
end
|
45
53
|
end
|
46
54
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bfrb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,12 +9,12 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-06-
|
12
|
+
date: 2011-06-10 00:00:00.000000000 -05:00
|
13
13
|
default_executable: bfrb
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: shoulda
|
17
|
-
requirement: &
|
17
|
+
requirement: &7574640 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: '0'
|
23
23
|
type: :development
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *7574640
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: bundler
|
28
|
-
requirement: &
|
28
|
+
requirement: &7573716 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ~>
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: 1.0.0
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *7573716
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: jeweler
|
39
|
-
requirement: &
|
39
|
+
requirement: &7572972 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ~>
|
@@ -44,10 +44,10 @@ dependencies:
|
|
44
44
|
version: 1.5.2
|
45
45
|
type: :development
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *7572972
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: rcov
|
50
|
-
requirement: &
|
50
|
+
requirement: &7559400 !ruby/object:Gem::Requirement
|
51
51
|
none: false
|
52
52
|
requirements:
|
53
53
|
- - ! '>='
|
@@ -55,7 +55,7 @@ dependencies:
|
|
55
55
|
version: '0'
|
56
56
|
type: :development
|
57
57
|
prerelease: false
|
58
|
-
version_requirements: *
|
58
|
+
version_requirements: *7559400
|
59
59
|
description: bfrb is a brainfuck interpreter written in Ruby.
|
60
60
|
email: ctoneal@gmail.com
|
61
61
|
executables:
|
@@ -93,7 +93,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
93
93
|
version: '0'
|
94
94
|
segments:
|
95
95
|
- 0
|
96
|
-
hash:
|
96
|
+
hash: -814124899
|
97
97
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
98
|
none: false
|
99
99
|
requirements:
|