Class: RLTK::CFG::Item
- Inherits:
-
Production
- Object
- Production
- RLTK::CFG::Item
- Defined in:
- lib/rltk/cfg.rb
Overview
The Item class represents a CFG production with dot in it.
Instance Attribute Summary collapse
-
#dot ⇒ Integer
readonly
Index of the next symbol in this item.
Attributes inherited from Production
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Compares two items.
-
#advance ⇒ Integer?
Moves the items dot forward by one if the end of the right-hand side hasn’t already been reached.
-
#at_end? ⇒ Boolean
Tests to see if the dot is at the end of the right-hand side.
-
#copy ⇒ Item
A new copy of this item.
-
#initialize(dot, *args) ⇒ Item
constructor
Instantiates a new Item object with a dot located before the symbol at index dot of the right-hand side.
-
#next_symbol ⇒ Symbol
Returns the symbol located after the dot.
-
#to_s(padding = 0) ⇒ String
Returns a string representation of this item.
Methods inherited from Production
Constructor Details
#initialize(dot, *args) ⇒ Item
Instantiates a new Item object with a dot located before the symbol at index dot of the right-hand side. The remaining arguments (args) should be as specified by Production#initialize.
598 599 600 601 602 603 |
# File 'lib/rltk/cfg.rb', line 598 def initialize(dot, *args) super(*args) # The Dot indicates the NEXT symbol to be read. @dot = dot end |
Instance Attribute Details
#dot ⇒ Integer (readonly)
Returns Index of the next symbol in this item.
589 590 591 |
# File 'lib/rltk/cfg.rb', line 589 def dot @dot end |
Instance Method Details
#==(other) ⇒ Boolean
Compares two items.
610 611 612 |
# File 'lib/rltk/cfg.rb', line 610 def ==(other) self.dot == other.dot and self.lhs == other.lhs and self.rhs == other.rhs end |
#advance ⇒ Integer?
Moves the items dot forward by one if the end of the right-hand side hasn’t already been reached.
618 619 620 621 622 |
# File 'lib/rltk/cfg.rb', line 618 def advance if @dot < @rhs.length @dot += 1 end end |
#at_end? ⇒ Boolean
Tests to see if the dot is at the end of the right-hand side.
627 628 629 |
# File 'lib/rltk/cfg.rb', line 627 def at_end? @dot == @rhs.length end |
#copy ⇒ Item
Returns A new copy of this item.
632 633 634 |
# File 'lib/rltk/cfg.rb', line 632 def copy Item.new(@dot, @id, @lhs, @rhs.clone) end |
#next_symbol ⇒ Symbol
Returns the symbol located after the dot.
639 640 641 |
# File 'lib/rltk/cfg.rb', line 639 def next_symbol @rhs[@dot] end |
#to_s(padding = 0) ⇒ String
Returns a string representation of this item.
648 649 650 |
# File 'lib/rltk/cfg.rb', line 648 def to_s(padding = 0) "#{format("%-#{padding}s", @lhs)} -> #{@rhs.map { |s| s.to_s }.insert(@dot, '·').join(' ') }" end |