Class: Rley::GFG::Vertex

Inherits:
Object
  • Object
show all
Defined in:
lib/rley/gfg/vertex.rb

Overview

Abstract class. Represents a vertex in a grammar flow graph Responsibilities:

  • To know its outgoing edges
  • To know its label

Direct Known Subclasses

ItemVertex, NonTerminalVertex

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeVertex

Constructor to extend in subclasses.



15
16
17
# File 'lib/rley/gfg/vertex.rb', line 15

def initialize()
  @edges = []
end

Instance Attribute Details

#edgesArray<Edge> (readonly)

The edges linking the successor vertices to this one.

Returns:

  • (Array<Edge>)

    The edge(s) linking this vertex to successor(s)



12
13
14
# File 'lib/rley/gfg/vertex.rb', line 12

def edges
  @edges
end

Instance Method Details

#add_edge(anEdge) ⇒ Object

Add an graph edge to this vertex.

Parameters:

  • anEdge (Edge)

    the edge to be added.



21
22
23
24
# File 'lib/rley/gfg/vertex.rb', line 21

def add_edge(anEdge)
  arrow = check_add_edge(anEdge)
  edges << arrow
end

#complete?Boolean

Determine if the vertex corresponds to an dotted item that has its dot at the end of a production (i.e. is a reduced item).

Returns:

  • (Boolean)

    true iff vertex corresponds to reduced item.



29
30
31
# File 'lib/rley/gfg/vertex.rb', line 29

def complete?()
  return false # Default implementation
end

#inspectString

Returns a string containing a human-readable representation of the vertex.

Returns:

  • (String)


36
37
38
39
40
41
42
43
44
# File 'lib/rley/gfg/vertex.rb', line 36

def inspect()
  result = +'#<'
  result << selfie
  edges.each { |e| result << e.inspect }
  result << specific_inspect
  result << '>'
  
  return result
end

#next_symbolGrmSymbol, NilClass

Retrieve the grammar symbol after the dot.

Returns:

  • (GrmSymbol, NilClass)

    The symbol or otherwise nil.



63
64
65
# File 'lib/rley/gfg/vertex.rb', line 63

def next_symbol()
  return nil # Default implementation
end

#prev_symbolGrmSymbol, NilClass

Retrieve the grammar symbol before the dot.

Returns:

  • (GrmSymbol, NilClass)

    The symbol or otherwise nil.



57
58
59
# File 'lib/rley/gfg/vertex.rb', line 57

def prev_symbol()
  return nil # Default implementation
end

#selfieString

Returns a string containing a human-readable representation of the vertex without the edges.

Returns:

  • (String)


49
50
51
52
53
# File 'lib/rley/gfg/vertex.rb', line 49

def selfie()
  result = +"#{self.class.name}:#{object_id}"
  result << %( label="#{label}")
  return result
end