Class: Aurum::Builder::LRItem
- Inherits:
-
Struct
- Object
- Struct
- Aurum::Builder::LRItem
- Defined in:
- lib/aurum/grammar/builder/set_of_items.rb
Instance Attribute Summary collapse
-
#dot_symbol ⇒ Object
readonly
Returns the value of attribute dot_symbol.
-
#is_handle ⇒ Object
(also: #handle?)
readonly
Returns the value of attribute is_handle.
-
#is_kernel ⇒ Object
(also: #kernel?)
readonly
Returns the value of attribute is_kernel.
-
#position ⇒ Object
Returns the value of attribute position.
-
#production ⇒ Object
Returns the value of attribute production.
-
#remaining ⇒ Object
readonly
Returns the value of attribute remaining.
Instance Method Summary collapse
-
#initialize(production, position = 0) ⇒ LRItem
constructor
A new instance of LRItem.
- #inspect ⇒ Object (also: #to_s)
- #next ⇒ Object
- #reducable?(symbol) ⇒ Boolean
Constructor Details
#initialize(production, position = 0) ⇒ LRItem
Returns a new instance of LRItem.
7 8 9 10 11 12 13 |
# File 'lib/aurum/grammar/builder/set_of_items.rb', line 7 def initialize(production, position = 0) super production, position @is_handle = position >= production.symbols.size @is_kernel = @is_handle || position != 0 || production.nonterminal == StartSymbol @dot_symbol = production.symbols[position] @remaining = @is_handle ? [] : production.symbols[position..-1] end |
Instance Attribute Details
#dot_symbol ⇒ Object (readonly)
Returns the value of attribute dot_symbol.
6 7 8 |
# File 'lib/aurum/grammar/builder/set_of_items.rb', line 6 def dot_symbol @dot_symbol end |
#is_handle ⇒ Object (readonly) Also known as: handle?
Returns the value of attribute is_handle.
6 7 8 |
# File 'lib/aurum/grammar/builder/set_of_items.rb', line 6 def is_handle @is_handle end |
#is_kernel ⇒ Object (readonly) Also known as: kernel?
Returns the value of attribute is_kernel.
6 7 8 |
# File 'lib/aurum/grammar/builder/set_of_items.rb', line 6 def is_kernel @is_kernel end |
#position ⇒ Object
Returns the value of attribute position
5 6 7 |
# File 'lib/aurum/grammar/builder/set_of_items.rb', line 5 def position @position end |
#production ⇒ Object
Returns the value of attribute production
5 6 7 |
# File 'lib/aurum/grammar/builder/set_of_items.rb', line 5 def production @production end |
#remaining ⇒ Object (readonly)
Returns the value of attribute remaining.
6 7 8 |
# File 'lib/aurum/grammar/builder/set_of_items.rb', line 6 def remaining @remaining end |
Instance Method Details
#inspect ⇒ Object Also known as: to_s
23 24 25 26 27 28 29 30 31 |
# File 'lib/aurum/grammar/builder/set_of_items.rb', line 23 def inspect result = "#{production.nonterminal.name} -> " production.symbols.each_with_index do |symbol, index| result << '.' if index == position result << symbol.inspect << ' ' end result << '.' if position >= production.symbols.length result end |
#next ⇒ Object
15 16 17 |
# File 'lib/aurum/grammar/builder/set_of_items.rb', line 15 def next LRItem.new(production, position + 1) end |
#reducable?(symbol) ⇒ Boolean
19 20 21 |
# File 'lib/aurum/grammar/builder/set_of_items.rb', line 19 def reducable?(symbol) (position == production.symbols.size - 1) && (@dot_symbol == symbol) end |