Class: Item
- Includes:
- Indexable
- Defined in:
- lib/rpdf2txt-rockit/parsetable_generation.rb
Constant Summary collapse
- @@empty_array =
Array.new
Instance Attribute Summary collapse
-
#lookahead ⇒ Object
readonly
Returns the value of attribute lookahead.
-
#position ⇒ Object
readonly
Returns the value of attribute position.
-
#production ⇒ Object
readonly
Returns the value of attribute production.
-
#symbol ⇒ Object
readonly
Returns the value of attribute symbol.
Attributes included from Indexable
Instance Method Summary collapse
- #calc_followers ⇒ Object
- #direct_following_symbols ⇒ Object
- #final? ⇒ Boolean
-
#initialize(production, position, lookahead = nil, nextItem = nil) ⇒ Item
constructor
A new instance of Item.
- #inspect ⇒ Object
- #lookahead_item(lookaheadSymbol) ⇒ Object
- #next_item ⇒ Object
- #suffix ⇒ Object
Constructor Details
#initialize(production, position, lookahead = nil, nextItem = nil) ⇒ Item
Returns a new instance of Item.
11 12 13 14 15 |
# File 'lib/rpdf2txt-rockit/parsetable_generation.rb', line 11 def initialize(production, position, lookahead = nil, nextItem = nil) @production, @position, @lookahead = production, position, lookahead @symbol = production.elements[position] @hash_value = [production, position, lookahead].hash end |
Instance Attribute Details
#lookahead ⇒ Object (readonly)
Returns the value of attribute lookahead.
9 10 11 |
# File 'lib/rpdf2txt-rockit/parsetable_generation.rb', line 9 def lookahead @lookahead end |
#position ⇒ Object (readonly)
Returns the value of attribute position.
9 10 11 |
# File 'lib/rpdf2txt-rockit/parsetable_generation.rb', line 9 def position @position end |
#production ⇒ Object (readonly)
Returns the value of attribute production.
9 10 11 |
# File 'lib/rpdf2txt-rockit/parsetable_generation.rb', line 9 def production @production end |
#symbol ⇒ Object (readonly)
Returns the value of attribute symbol.
9 10 11 |
# File 'lib/rpdf2txt-rockit/parsetable_generation.rb', line 9 def symbol @symbol end |
Instance Method Details
#calc_followers ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/rpdf2txt-rockit/parsetable_generation.rb', line 21 def calc_followers return @@empty_array if position >= production.elements.length-1 elements = production.elements[position+1..-1] followers = Array.new elements.each do |e| followers.push e return followers unless e.derives_epsilon? end followers end |
#direct_following_symbols ⇒ Object
17 18 19 |
# File 'lib/rpdf2txt-rockit/parsetable_generation.rb', line 17 def direct_following_symbols @direct_following_symbols || (@direct_following_symbols = calc_followers) end |
#final? ⇒ Boolean
42 43 44 |
# File 'lib/rpdf2txt-rockit/parsetable_generation.rb', line 42 def final? next_item == nil end |
#inspect ⇒ Object
54 55 56 57 58 59 60 61 |
# File 'lib/rpdf2txt-rockit/parsetable_generation.rb', line 54 def inspect endpos = ((@position >= production.elements.length) or (@position == 0)) production.nonterminal.inspect + "->" + inspect_elements(production.elements[0...@position]) + (endpos ? "." : " .") + inspect_elements(production.elements[@position..-1]) end |
#lookahead_item(lookaheadSymbol) ⇒ Object
50 51 52 |
# File 'lib/rpdf2txt-rockit/parsetable_generation.rb', line 50 def lookahead_item(lookaheadSymbol) make_new_item(production, position, lookaheadSymbol, next_item) end |
#next_item ⇒ Object
46 47 48 |
# File 'lib/rpdf2txt-rockit/parsetable_generation.rb', line 46 def next_item @next_item || (@next_item = calc_next_item) end |
#suffix ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/rpdf2txt-rockit/parsetable_generation.rb', line 34 def suffix if position < production.elements.length-1 production.elements[position+1..-1] else nil end end |