Class: LexerKit::Builder::Compiler
- Inherits:
-
Object
- Object
- LexerKit::Builder::Compiler
- Defined in:
- lib/lexer_kit/builder/compiler.rb
Overview
Compiler transforms Builder definitions into IR::CompiledProgram.
Instance Method Summary collapse
- #compile ⇒ Object
-
#initialize(builder) ⇒ Compiler
constructor
A new instance of Compiler.
Constructor Details
#initialize(builder) ⇒ Compiler
Returns a new instance of Compiler.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/lexer_kit/builder/compiler.rb', line 7 def initialize(builder) @builder = builder @instructions = [] @constant_pool = IR::ConstantPool.new @jump_tables = [] @dfa_tables = [] @token_names = [] @token_ids = {} @mode_names = [] @mode_ids = {} @keyword_tables = [] @modes = {} @labels = {} @label_counter = 0 @pending_jumps = [] @pending_dfa_run_if_match = [] @pending_match_literal_or_jump = [] @pending_emit_and_jump = [] @pending_set_match = [] @pending_literal_trie_commit = [] @pending_trie_entries = [] @dfa_cache = {} # pattern => dfa_id (cache for regex DFAs) @keyword_cache = {} # token_def => table_id (cache for keyword tables) end |
Instance Method Details
#compile ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/lexer_kit/builder/compiler.rb', line 32 def compile # Assign token IDs assign_token_ids # Compile each mode @builder.mode_defs.each do |_name, mode_def| compile_mode(mode_def) end # Add HALT at end emit(IR::Opcode::HALT) # Resolve pending jumps resolve_jumps finalize_literal_tries IR::CompiledProgram.new( instructions: @instructions, dfa_tables: @dfa_tables, jump_tables: @jump_tables, constant_pool: @constant_pool, modes: @modes, token_names: @token_names, mode_names: @mode_names, keyword_tables: @keyword_tables, token_meta: , version: @builder.version ) end |