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.
810 811 812 813 814 815 816 817 818 |
# File 'lib/racc/state.rb', line 810 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.
871 872 873 |
# File 'lib/racc/state.rb', line 871 def accept @accept end |
#error ⇒ Object (readonly)
Returns the value of attribute error.
872 873 874 |
# File 'lib/racc/state.rb', line 872 def error @error end |
Instance Method Details
#each_reduce(&block) ⇒ Object
848 849 850 |
# File 'lib/racc/state.rb', line 848 def each_reduce(&block) @reduce.each(&block) end |
#each_shift(&block) ⇒ Object
867 868 869 |
# File 'lib/racc/state.rb', line 867 def each_shift(&block) @shift.each(&block) end |
#init ⇒ Object
820 821 822 823 824 825 826 827 828 829 |
# File 'lib/racc/state.rb', line 820 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
835 836 837 838 839 840 841 842 843 844 845 846 |
# File 'lib/racc/state.rb', line 835 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
831 832 833 |
# File 'lib/racc/state.rb', line 831 def reduce_n @reduce.size end |
#shift(i) ⇒ Object
856 857 858 859 860 861 862 863 864 865 |
# File 'lib/racc/state.rb', line 856 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
852 853 854 |
# File 'lib/racc/state.rb', line 852 def shift_n @shift.size end |