Class: Aurum::ParsingTableGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/aurum/parsing_table_generator.rb

Defined Under Namespace

Classes: PrecedenceTable, State

Constant Summary collapse

DEFAULT_ASSOCIATIVITIES =
{:left => [], :right => []}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(definition, precedences = [], associativities = DEFAULT_ASSOCIATIVITIES) ⇒ ParsingTableGenerator

Returns a new instance of ParsingTableGenerator.



19
20
21
22
# File 'lib/aurum/parsing_table_generator.rb', line 19

def initialize(definition, precedences = [], associativities = DEFAULT_ASSOCIATIVITIES)
    @definition = definition
    @precedence_table = PrecedenceTable.new precedences, associativities
end

Instance Attribute Details

#productionsObject (readonly)

Returns the value of attribute productions.



15
16
17
# File 'lib/aurum/parsing_table_generator.rb', line 15

def productions
  @productions
end

#symbolsObject (readonly)

Returns the value of attribute symbols.



15
16
17
# File 'lib/aurum/parsing_table_generator.rb', line 15

def symbols
  @symbols
end

Instance Method Details

#parsing_tableObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/aurum/parsing_table_generator.rb', line 31

def parsing_table
	Log.debug 'Start constructing LR(0) automata.'
    construct_LR0_automata
			Log.debug "Finished, #{@states.size} LR(0) states constructed."
			Log.debug "#{@inconsistents.size} inconsistent states found."
    if @inconsistents.size > 0
        compute_LALR_1_lookahead
        compute_LALR_n_lookahead unless @conflicts.empty?
    end
    parsing_table = []
    for state in @states do
        actions = Hash.new default_action(state)
        state.actions.each {|symbol, action| actions[symbol] = action.to_a.first}
        parsing_table << actions
    end
    return parsing_table, @lookahead_level
end

#start_from(start) ⇒ Object



24
25
26
27
28
29
# File 'lib/aurum/parsing_table_generator.rb', line 24

def start_from start
	initialize_augmented_grammar start
    compute_nullable_symbols
    compute_first_sets
    self
end