Class: Racc::ActionTable
Overview
The table of LALR actions. Actions are either of Shift, Reduce, Accept and Error.
Instance Attribute Summary collapse
-
#accept ⇒ Object
readonly
Returns the value of attribute accept.
-
#error ⇒ Object
readonly
Returns the value of attribute error.
Instance Method Summary collapse
- #each_reduce(&block) ⇒ Object
- #each_shift(&block) ⇒ Object
- #init ⇒ Object
-
#initialize(rt, st) ⇒ ActionTable
constructor
A new instance of ActionTable.
- #reduce(i) ⇒ Object
- #reduce_n ⇒ Object
- #shift(i) ⇒ Object
- #shift_n ⇒ Object
Constructor Details
#initialize(rt, st) ⇒ ActionTable
Returns a new instance of ActionTable.
817 818 819 820 821 822 823 824 825 |
# File 'lib/racc/state.rb', line 817 def initialize(rt, st) @grammar = rt @statetable = st @reduce = [] @shift = [] @accept = nil @error = nil end |
Instance Attribute Details
#accept ⇒ Object (readonly)
Returns the value of attribute accept.
878 879 880 |
# File 'lib/racc/state.rb', line 878 def accept @accept end |
#error ⇒ Object (readonly)
Returns the value of attribute error.
879 880 881 |
# File 'lib/racc/state.rb', line 879 def error @error end |
Instance Method Details
#each_reduce(&block) ⇒ Object
855 856 857 |
# File 'lib/racc/state.rb', line 855 def each_reduce(&block) @reduce.each(&block) end |
#each_shift(&block) ⇒ Object
874 875 876 |
# File 'lib/racc/state.rb', line 874 def each_shift(&block) @shift.each(&block) end |
#init ⇒ Object
827 828 829 830 831 832 833 834 835 836 |
# File 'lib/racc/state.rb', line 827 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
842 843 844 845 846 847 848 849 850 851 852 853 |
# File 'lib/racc/state.rb', line 842 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_n ⇒ Object
838 839 840 |
# File 'lib/racc/state.rb', line 838 def reduce_n @reduce.size end |
#shift(i) ⇒ Object
863 864 865 866 867 868 869 870 871 872 |
# File 'lib/racc/state.rb', line 863 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_n ⇒ Object
859 860 861 |
# File 'lib/racc/state.rb', line 859 def shift_n @shift.size end |