Class: Brainfuck::Stage::BfFile

Inherits:
Rubinius::Compiler::Stage
  • Object
show all
Defined in:
lib/brainfuck/stages.rb

Overview

This stage takes a brainfuck filename and produces a ruby array containing representation of the brainfuck source.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(compiler, last) ⇒ BfFile

Returns a new instance of BfFile.



150
151
152
153
154
# File 'lib/brainfuck/stages.rb', line 150

def initialize(compiler, last)
  super
  @print = Compiler::Print.new
  compiler.parser = self
end

Instance Attribute Details

#filenameObject (readonly)

Returns the value of attribute filename.



147
148
149
# File 'lib/brainfuck/stages.rb', line 147

def filename
  @filename
end

#lineObject (readonly)

Returns the value of attribute line.



147
148
149
# File 'lib/brainfuck/stages.rb', line 147

def line
  @line
end

Returns the value of attribute print.



148
149
150
# File 'lib/brainfuck/stages.rb', line 148

def print
  @print
end

Instance Method Details

#input(filename, line = 1) ⇒ Object



156
157
158
159
# File 'lib/brainfuck/stages.rb', line 156

def input(filename, line = 1)
  @filename = filename
  @line = line
end

#runObject



161
162
163
164
165
166
# File 'lib/brainfuck/stages.rb', line 161

def run
  code = Lexer.clean(File.read(@filename))
  @output = Lexer.new.tokenize(code)
  pp(@output) if @print.sexp?
  run_next
end