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::LanguageParser
Get a new or the cached instance of this class.
-
.parse(code) ⇒ Brainfucktt::Parser
Parse the given Brainfuck code.
-
.run(code, 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(tree) ⇒ Parser
constructor
A new instance of Parser.
-
#run(options = {}) ⇒ Object
Run the parsed Brainfuck code.
Constructor Details
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
44 45 46 |
# File 'lib/brainfucktt/parser.rb', line 44 def data @data end |
#input ⇒ Object (readonly)
Returns the value of attribute input.
44 45 46 |
# File 'lib/brainfucktt/parser.rb', line 44 def input @input end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
44 45 46 |
# File 'lib/brainfucktt/parser.rb', line 44 def output @output end |
#pointer ⇒ Object
Returns the value of attribute pointer.
45 46 47 |
# File 'lib/brainfucktt/parser.rb', line 45 def pointer @pointer end |
#tree ⇒ Object (readonly)
Returns the value of attribute tree.
44 45 46 |
# File 'lib/brainfucktt/parser.rb', line 44 def tree @tree end |
Class Method Details
.instance ⇒ Brainfucktt::LanguageParser
Get a new or the cached instance of this class.
20 21 22 |
# File 'lib/brainfucktt/parser.rb', line 20 def instance @instance ||= LanguageParser.new end |
.parse(code) ⇒ Brainfucktt::Parser
Parse the given Brainfuck code.
29 30 31 32 33 34 |
# File 'lib/brainfucktt/parser.rb', line 29 def parse(code) tree = instance.parse(code) raise ParserError, instance unless tree new(tree) end |
.run(code, options = {}) ⇒ Object
Parse and run the given Brainfuck code.
39 40 41 |
# File 'lib/brainfucktt/parser.rb', line 39 def run(code, ={}) parse(code).run() end |
Instance Method Details
#byte ⇒ Brainfucktt::Byte
Returns the Byte instance within the @data collection at pointer.
65 66 67 |
# File 'lib/brainfucktt/parser.rb', line 65 def byte @data[@pointer] end |
#byte=(value) ⇒ Brainfucktt::Byte
Set the value of the Byte instance within the @data collection at pointer.
72 73 74 |
# File 'lib/brainfucktt/parser.rb', line 72 def byte=(value) @data[@pointer] = value end |
#run(options = {}) ⇒ Object
Run the parsed Brainfuck code.
55 56 57 58 59 60 |
# File 'lib/brainfucktt/parser.rb', line 55 def run(={}) = { input: STDIN, output: STDOUT }.merge( () ) @input, @output = .values_at(:input, :output) @tree.run(self) end |