Class: Vm::Translator

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

Instance Method Summary collapse

Constructor Details

#initialize(text, object_name) ⇒ Translator

Returns a new instance of Translator.



7
8
9
10
# File 'lib/hackasm/vm/translator.rb', line 7

def initialize(text, object_name)
  @text = text
  @object_name = object_name
end

Instance Method Details

#translateObject



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

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