Class: Assembler::Translator

Inherits:
Object
  • Object
show all
Defined in:
lib/hackasm/assembler/translator.rb

Instance Method Summary collapse

Constructor Details

#initialize(text) ⇒ Translator

Returns a new instance of Translator.



9
10
11
# File 'lib/hackasm/assembler/translator.rb', line 9

def initialize(text)
  @text = text
end

Instance Method Details

#translateObject



13
14
15
16
17
18
19
20
# File 'lib/hackasm/assembler/translator.rb', line 13

def translate
  expressions = parser.parse(@text)
  expressions.map do |expression|
    process_instruction(expression)
  end.compact.join("\n") << "\n"
rescue Parslet::ParseFailed => failure
  failure.parse_failure_cause.ascii_tree
end