class Rley::GFG::Vertex
Abstract class. Represents a vertex in a grammar flow graph Responsibilities:
-
To know its outgoing edges
-
To know its label
Attributes
The edges linking the successor vertices to this one. @return [Array<Edge>] The edge(s) linking this vertex to successor(s)
Return the object id in string format @return [String]
Public Class Methods
Source
# File lib/rley/gfg/vertex.rb, line 19 def initialize @edges = [] @oid_str = object_id.to_s end
Constructor to extend in subclasses.
Public Instance Methods
Source
# File lib/rley/gfg/vertex.rb, line 67 def add_edge(anEdge) arrow = check_add_edge(anEdge) edges << arrow end
Add an graph edge to this vertex. @param anEdge [Edge] the edge to be added.
Source
# File lib/rley/gfg/vertex.rb, line 27 def complete? false # Default implementation end
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). @return [Boolean] true iff vertex corresponds to reduced item.
Source
# File lib/rley/gfg/vertex.rb, line 79 def dotted_item raise NotImplementedError end
Source
# File lib/rley/gfg/vertex.rb, line 34 def inspect result = +'#<' result << selfie edges.each { |e| result << e.inspect } result << specific_inspect result << '>' result end
Returns a string containing a human-readable representation of the vertex. @return [String]
Source
# File lib/rley/gfg/vertex.rb, line 75 def label raise NotImplementedError end
The label of this vertex. It is the same as the label of the corresponding dotted item. @return [String] Label for this vertex
Source
# File lib/rley/gfg/vertex.rb, line 61 def next_symbol nil # Default implementation end
Retrieve the grammar symbol after the dot. @return [GrmSymbol, NilClass] The symbol or otherwise nil.
Source
# File lib/rley/gfg/vertex.rb, line 55 def prev_symbol nil # Default implementation end
Retrieve the grammar symbol before the dot. @return [GrmSymbol, NilClass] The symbol or otherwise nil.
Source
# File lib/rley/gfg/vertex.rb, line 47 def selfie result = +"#{self.class.name}:#{object_id}" result << %( label="#{label}") result end
Returns a string containing a human-readable representation of the vertex without the edges. @return [String]
Protected Instance Methods
Source
# File lib/rley/gfg/vertex.rb, line 88 def check_add_edge(anEdge) raise StandardError, 'At most one edge accepted' unless edges.empty? anEdge end
Validation method for adding an outgoing edge to the vertex. Vertices will accept an indegree and outdegree of at most one unless this method is overridden in subclasses