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.



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

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.



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

def accept
  @accept
end

#errorObject (readonly)

Returns the value of attribute error.



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

def error
  @error
end

Instance Method Details

#each_reduce(&block) ⇒ Object



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

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

#each_shift(&block) ⇒ Object



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

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

#initObject



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

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



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

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



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

def reduce_n
  @reduce.size
end

#shift(i) ⇒ Object



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

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



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

def shift_n
  @shift.size
end