summaryrefslogtreecommitdiff
path: root/tool/lrama/lib/lrama/state/reduce.rb
diff options
context:
space:
mode:
Diffstat (limited to 'tool/lrama/lib/lrama/state/reduce.rb')
-rw-r--r--tool/lrama/lib/lrama/state/reduce.rb38
1 files changed, 38 insertions, 0 deletions
diff --git a/tool/lrama/lib/lrama/state/reduce.rb b/tool/lrama/lib/lrama/state/reduce.rb
new file mode 100644
index 0000000000..a2b7c26cfe
--- /dev/null
+++ b/tool/lrama/lib/lrama/state/reduce.rb
@@ -0,0 +1,38 @@
+# frozen_string_literal: true
+
+module Lrama
+ class State
+ class Reduce
+ # https://www.gnu.org/software/bison/manual/html_node/Default-Reductions.html
+ attr_reader :item, :look_ahead, :not_selected_symbols
+ attr_accessor :default_reduction
+
+ def initialize(item)
+ @item = item
+ @look_ahead = nil
+ @not_selected_symbols = []
+ end
+
+ def rule
+ @item.rule
+ end
+
+ def look_ahead=(look_ahead)
+ @look_ahead = look_ahead.freeze
+ end
+
+ def add_not_selected_symbol(sym)
+ @not_selected_symbols << sym
+ end
+
+ def selected_look_ahead
+ if @look_ahead
+ # @type ivar @look_ahead: Array<Grammar::Symbol>
+ @look_ahead - @not_selected_symbols
+ else
+ []
+ end
+ end
+ end
+ end
+end