Class: Aurum::ParsingTableGenerator::State

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(elements) ⇒ State

Returns a new instance of State.



391
392
393
394
395
396
397
398
399
400
401
# File 'lib/aurum/parsing_table_generator.rb', line 391

def initialize elements
    super elements
        @actions, @predsucceors, @read_reduce = {}, [], nil
        @handles, @non_handles, @kernels, @direct_read = [], [], [], [].to_set    
        for item in elements
          (item.is_handle ? @handles : @non_handles) << item 
          @kernels << item if item.is_kernel
          @direct_read << item.dot_symbol if item.dot_symbol 
        end                
        @read_reduce = first.production if size == 1 && first.is_handle
end

Instance Attribute Details

#actionsObject (readonly)

Returns the value of attribute actions.



390
391
392
# File 'lib/aurum/parsing_table_generator.rb', line 390

def actions
  @actions
end

#direct_readObject (readonly)

Returns the value of attribute direct_read.



390
391
392
# File 'lib/aurum/parsing_table_generator.rb', line 390

def direct_read
  @direct_read
end

#handlesObject (readonly)

Returns the value of attribute handles.



390
391
392
# File 'lib/aurum/parsing_table_generator.rb', line 390

def handles
  @handles
end

#kernelsObject (readonly)

Returns the value of attribute kernels.



390
391
392
# File 'lib/aurum/parsing_table_generator.rb', line 390

def kernels
  @kernels
end

#non_handlesObject (readonly)

Returns the value of attribute non_handles.



390
391
392
# File 'lib/aurum/parsing_table_generator.rb', line 390

def non_handles
  @non_handles
end

#read_reduceObject (readonly)

Returns the value of attribute read_reduce.



390
391
392
# File 'lib/aurum/parsing_table_generator.rb', line 390

def read_reduce
  @read_reduce
end

Instance Method Details

#==(other) ⇒ Object



442
443
444
445
446
# File 'lib/aurum/parsing_table_generator.rb', line 442

def == other
  return false unless other.kind_of?(State) && (@kernels.size == other.kernels.size)
        return true if equal? other  
    @kernels.all? {|x| other.kernels.include? x}
end

#[](symbol) ⇒ Object



403
404
405
406
# File 'lib/aurum/parsing_table_generator.rb', line 403

def [] symbol
    @actions[symbol] = Set.new([]) unless @actions.has_key? symbol
    @actions[symbol]
end

#conflict?Boolean

Returns:

  • (Boolean)


412
413
414
# File 'lib/aurum/parsing_table_generator.rb', line 412

def conflict?
  inconsistent? && @actions.any? {|symbol, actions| actions.length > 1}
end

#conflicted_actionsObject



416
417
418
# File 'lib/aurum/parsing_table_generator.rb', line 416

def conflicted_actions
    @actions.find_all {|symbol, actions| actions.length > 1}
end

#goto(symbol) ⇒ Object



424
425
426
427
# File 'lib/aurum/parsing_table_generator.rb', line 424

def goto symbol
    shift = self[symbol].find {|x| x.kind_of? Aurum::ShiftAction }
    shift.state if shift
end

#inconsistent?Boolean

Returns:

  • (Boolean)


408
409
410
# File 'lib/aurum/parsing_table_generator.rb', line 408

def inconsistent?
  @handles.size > 1 || (@handles.size == 1 && @kernels.size != 1) 
end

#only_shift?(symbol) ⇒ Boolean

Returns:

  • (Boolean)


420
421
422
# File 'lib/aurum/parsing_table_generator.rb', line 420

def only_shift? symbol
    !self[symbol].empty? && @actions[symbol].all? {|x| x.kind_of? ShiftAction}
end

#predsucceors(symbols = nil) ⇒ Object



429
430
431
432
433
434
435
436
437
438
439
440
# File 'lib/aurum/parsing_table_generator.rb', line 429

def predsucceors(symbols = nil)
    symbols or return @predsucceors
    result = [self]
    for symbol in symbols
      new_result = []
          for x in result
            new_result |= x.predsucceors.find_all {|predsucceor| predsucceor.any? {|item| item.dot_symbol == symbol}}
          end
        result.replace new_result
    end
    result
end