Class: Base::Compiler

Inherits:
Object
  • Object
show all
Defined in:
lib/base/compiler.rb

Constant Summary collapse

Error =
Class.new(StandardError)

Instance Method Summary collapse

Constructor Details

#initializeCompiler

Returns a new instance of Compiler.



5
6
7
8
9
10
# File 'lib/base/compiler.rb', line 5

def initialize
  @parsing = []
  @memory = []
  @labels = {}
  @macros = {}
end

Instance Method Details

#compile(file) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/base/compiler.rb', line 12

def compile(file)
  lines = File.read(file).split("\n")
  parse(lines)

  main = @labels["main"] || 0
  [main] + @memory
end