Class: Brainfucktt::Parser
- Inherits:
-
Object
- Object
- Brainfucktt::Parser
- Includes:
- ConversionHelpers
- Defined in:
- lib/brainfucktt/parser.rb
Overview
The Brainfuck parser.
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#input ⇒ Object
readonly
Returns the value of attribute input.
-
#output ⇒ Object
readonly
Returns the value of attribute output.
-
#pointer ⇒ Object
Returns the value of attribute pointer.
-
#tree ⇒ Object
readonly
Returns the value of attribute tree.
Class Method Summary collapse
-
.instance ⇒ Brainfucktt::Parser
Get a new or the cached instance of this class.
-
.language_parser ⇒ Brainfucktt::Parser
Get a new or the cached instance of this class.
-
.parse(code) ⇒ Brainfucktt::Parser
Parse the given Brainfuck code.
-
.run(code = nil, options = {}) ⇒ Object
Parse and run the given Brainfuck code.
Instance Method Summary collapse
-
#byte ⇒ Brainfucktt::Byte
Returns the Byte instance within the @data collection at pointer.
-
#byte=(value) ⇒ Brainfucktt::Byte
Set the value of the Byte instance within the @data collection at pointer.
-
#initialize(options = {}) ⇒ Parser
constructor
A new instance of Parser.
-
#parse(code) ⇒ Brainfucktt::Parser
Parse the given Brainfuck code.
-
#run(code = nil, options = {}) ⇒ Object
Run the parsed Brainfuck code.
Constructor Details
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
50 51 52 |
# File 'lib/brainfucktt/parser.rb', line 50 def data @data end |
#input ⇒ Object (readonly)
Returns the value of attribute input.
50 51 52 |
# File 'lib/brainfucktt/parser.rb', line 50 def input @input end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
50 51 52 |
# File 'lib/brainfucktt/parser.rb', line 50 def output @output end |
#pointer ⇒ Object
Returns the value of attribute pointer.
51 52 53 |
# File 'lib/brainfucktt/parser.rb', line 51 def pointer @pointer end |
#tree ⇒ Object (readonly)
Returns the value of attribute tree.
50 51 52 |
# File 'lib/brainfucktt/parser.rb', line 50 def tree @tree end |
Class Method Details
.instance ⇒ Brainfucktt::Parser
Get a new or the cached instance of this class.
20 21 22 |
# File 'lib/brainfucktt/parser.rb', line 20 def instance @instance ||= new end |
.language_parser ⇒ Brainfucktt::Parser
Get a new or the cached instance of this class.
27 28 29 |
# File 'lib/brainfucktt/parser.rb', line 27 def language_parser @language_parser ||= LanguageParser.new end |
.parse(code) ⇒ Brainfucktt::Parser
Parse the given Brainfuck code.
36 37 38 |
# File 'lib/brainfucktt/parser.rb', line 36 def parse(code) instance.parse(code) end |
.run(code = nil, options = {}) ⇒ Object
Parse and run the given Brainfuck code.
44 45 46 |
# File 'lib/brainfucktt/parser.rb', line 44 def run(code=nil, ={}) instance.run(code, ) end |
Instance Method Details
#byte ⇒ Brainfucktt::Byte
Returns the Byte instance within the @data collection at pointer.
89 90 91 |
# File 'lib/brainfucktt/parser.rb', line 89 def byte @data[@pointer] end |
#byte=(value) ⇒ Brainfucktt::Byte
Set the value of the Byte instance within the @data collection at pointer.
96 97 98 |
# File 'lib/brainfucktt/parser.rb', line 96 def byte=(value) @data[@pointer] = value end |
#parse(code) ⇒ Brainfucktt::Parser
Parse the given Brainfuck code.
79 80 81 82 83 84 |
# File 'lib/brainfucktt/parser.rb', line 79 def parse(code) @tree = self.class.language_parser.parse(code) raise ParserError, self unless @tree self end |
#run(code = nil, options = {}) ⇒ Object
Run the parsed Brainfuck code.
65 66 67 68 69 70 71 72 |
# File 'lib/brainfucktt/parser.rb', line 65 def run(code=nil, ={}) = { :input => @input, :output => @output }.merge( () ) @input, @output = .values_at(:input, :output) parse(code) unless code.nil? @tree.run(self) end |