Class: Aurum::Builder::ParsingTableBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/aurum/grammar/builder/parsing_table_builder.rb

Instance Method Summary collapse

Constructor Details

#initialize(augmented_grammar, logger) ⇒ ParsingTableBuilder

Returns a new instance of ParsingTableBuilder.



12
13
14
15
16
# File 'lib/aurum/grammar/builder/parsing_table_builder.rb', line 12

def initialize augmented_grammar, logger
  @augmented_grammar, @logger = augmented_grammar, logger
  @lookahead_level, @states = 0, []
  @inconsistent_states = []
end

Instance Method Details

#buildObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/aurum/grammar/builder/parsing_table_builder.rb', line 18

def build
  construct_automata
  unless @inconsistent_states.empty?
    @augmented_grammar.compute_nullables
    @augmented_grammar.compute_first_sets
    @conflict_states = [].to_set
    @follow_set_calculator = DigraphTraverser.new do |config|
      (config.symbol == StartSymbol) ? [false, [Aurum::Grammar::EOF], 65535] : [true, nil, nil]
    end
    for inconsistent_state in @inconsistent_states do
      determine_lookaheads_for(inconsistent_state)
      @conflict_states << inconsistent_state if inconsistent_state.conflict?
    end
    unless @conflict_states.empty?
      for conflict_state in @conflict_states do
        for lookahead in conflict_state.conflicts do
          @state_lookahead_level = 2
          resolve_conflicts_for(conflict_state, lookahead, Sources.new(conflict_state, lookahead))
          @lookahead_level = @state_lookahead_level if @state_lookahead_level > @lookahead_level
        end
      end
    end
  end
  construct_parsing_table
end