Class: Electr::Compiler

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

Instance Method Summary collapse

Instance Method Details

#compile_to_ast(code) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/electr/compiler.rb', line 5

def compile_to_ast(code)
  units = []
  tokenizer = Tokenizer.new(code)
  lexer = Lexer.new
  while tokenizer.has_more_token?
    units << lexer.lexify(tokenizer.next_token)
  end

  syntaxer = Syntaxer.new(units.dup)
  ast = syntaxer.run
end

#compile_to_pn(code) ⇒ Object

To Prefix Notation.



18
19
20
21
# File 'lib/electr/compiler.rb', line 18

def compile_to_pn(code)
  ast = compile_to_ast(code)
  ast.to_pn
end