Class: Aurum::Builder::LRItem

Inherits:
Struct
  • Object
show all
Defined in:
lib/aurum/grammar/builder/set_of_items.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_symbolObject (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_handleObject (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_kernelObject (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

#positionObject

Returns the value of attribute position

Returns:

  • (Object)

    the current value of position



5
6
7
# File 'lib/aurum/grammar/builder/set_of_items.rb', line 5

def position
  @position
end

#productionObject

Returns the value of attribute production

Returns:

  • (Object)

    the current value of production



5
6
7
# File 'lib/aurum/grammar/builder/set_of_items.rb', line 5

def production
  @production
end

#remainingObject (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

#inspectObject 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

#nextObject



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

Returns:

  • (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