Class: Electr::Compiler
- Inherits:
-
Object
- Object
- Electr::Compiler
- Defined in:
- lib/electr/compiler.rb
Overview
The toolchain that takes a code at input and outputs it in another structure.
The compiler could outputs the code either as an AST or as a list of element in the prefix notation.
Class Method Summary collapse
- .compile_to_ast(code) ⇒ Object
-
.compile_to_pn(code) ⇒ Object
To Prefix Notation.
Class Method Details
.compile_to_ast(code) ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/electr/compiler.rb', line 10 def self.compile_to_ast(code) units = [] tokenizer = Tokenizer.new(code) while tokenizer.has_more_token? units << Lexer.lexify(tokenizer.next_token) end syntaxer = Syntaxer.new(units.dup) syntaxer.run end |
.compile_to_pn(code) ⇒ Object
To Prefix Notation.
21 22 23 24 |
# File 'lib/electr/compiler.rb', line 21 def self.compile_to_pn(code) ast = self.compile_to_ast(code) ast.to_pn end |