Class: Racc::ActionTable

Inherits:
Object show all
Defined in:
lib/racc/state.rb

Overview

The table of LALR actions. Actions are either of Shift, Reduce, Accept and Error.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rt, st) ⇒ ActionTable

Returns a new instance of ActionTable.


812
813
814
815
816
817
818
819
820
# File 'lib/racc/state.rb', line 812

def initialize(rt, st)
  @grammar = rt
  @statetable = st

  @reduce = []
  @shift = []
  @accept = nil
  @error = nil
end

Instance Attribute Details

#acceptObject (readonly)

Returns the value of attribute accept


873
874
875
# File 'lib/racc/state.rb', line 873

def accept
  @accept
end

#errorObject (readonly)

Returns the value of attribute error


874
875
876
# File 'lib/racc/state.rb', line 874

def error
  @error
end

Instance Method Details

#each_reduce(&block) ⇒ Object


850
851
852
# File 'lib/racc/state.rb', line 850

def each_reduce(&block)
  @reduce.each(&block)
end

#each_shift(&block) ⇒ Object


869
870
871
# File 'lib/racc/state.rb', line 869

def each_shift(&block)
  @shift.each(&block)
end

#initObject


822
823
824
825
826
827
828
829
830
831
# File 'lib/racc/state.rb', line 822

def init
  @grammar.each do |rule|
    @reduce.push Reduce.new(rule)
  end
  @statetable.each do |state|
    @shift.push Shift.new(state)
  end
  @accept = Accept.new
  @error = Error.new
end

#reduce(i) ⇒ Object


837
838
839
840
841
842
843
844
845
846
847
848
# File 'lib/racc/state.rb', line 837

def reduce(i)
  case i
  when Rule    then i = i.ident
  when Integer then ;
  else
    raise "racc: fatal: wrong class #{i.class} for reduce"
  end

  r = @reduce[i] or raise "racc: fatal: reduce action #{i.inspect} not exist"
  r.incref
  r
end

#reduce_nObject


833
834
835
# File 'lib/racc/state.rb', line 833

def reduce_n
  @reduce.size
end

#shift(i) ⇒ Object


858
859
860
861
862
863
864
865
866
867
# File 'lib/racc/state.rb', line 858

def shift(i)
  case i
  when State   then i = i.ident
  when Integer then ;
  else
    raise "racc: fatal: wrong class #{i.class} for shift"
  end

  @shift[i] or raise "racc: fatal: shift action #{i} does not exist"
end

#shift_nObject


854
855
856
# File 'lib/racc/state.rb', line 854

def shift_n
  @shift.size
end