Sha256: 20eb132818e269f4792083cd6bd7ede4ea51802bb0c08c8ed87eb2b24c00eee6

Contents?: true

Size: 1.45 KB

Versions: 22

Compression:

Stored size: 1.45 KB

Contents

module Rley # This module is used as a namespace
  module GFG # This module is used as a namespace
    # Abstract class. Represents a vertex in a grammar flow graph
    # Responsibilities:
    # - To know its outgoing edges
    # - To know its label
    class Vertex
      # The edges linking the successor vertices to this one.
      attr_reader :edges
      
      def initialize()
        @edges = []
      end
      
      # Add an graph edge to this vertex
      def add_edge(anEdge)
        arrow = check_add_edge(anEdge)
        edges << arrow
      end
      
      # Returns true iff the vertex corresponds to an dotted item that has
      # its dot at the end of a production (i.e. is a reduced item).
      def complete?()
        return false # Default implementation
      end
      
      # Return the symbol before the dot else nil.
      def prev_symbol()
        return nil # Default implementation
      end      
      
      # Return the symbol after the dot else nil.
      def next_symbol()
        return nil # Default implementation
      end
      
      protected

      # 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
      def check_add_edge(anEdge)
        raise StandardError, 'At most one edge accepted' unless edges.empty?
        return anEdge
      end
    end # class
  end # module
end # module

# End of file

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
rley-0.5.04 lib/rley/gfg/vertex.rb
rley-0.5.03 lib/rley/gfg/vertex.rb
rley-0.5.02 lib/rley/gfg/vertex.rb
rley-0.5.01 lib/rley/gfg/vertex.rb
rley-0.5.00 lib/rley/gfg/vertex.rb
rley-0.4.08 lib/rley/gfg/vertex.rb
rley-0.4.07 lib/rley/gfg/vertex.rb
rley-0.4.06 lib/rley/gfg/vertex.rb
rley-0.4.05 lib/rley/gfg/vertex.rb
rley-0.4.04 lib/rley/gfg/vertex.rb
rley-0.4.03 lib/rley/gfg/vertex.rb
rley-0.4.02 lib/rley/gfg/vertex.rb
rley-0.4.01 lib/rley/gfg/vertex.rb
rley-0.4.00 lib/rley/gfg/vertex.rb
rley-0.3.12 lib/rley/gfg/vertex.rb
rley-0.3.11 lib/rley/gfg/vertex.rb
rley-0.3.10 lib/rley/gfg/vertex.rb
rley-0.3.09 lib/rley/gfg/vertex.rb
rley-0.3.08 lib/rley/gfg/vertex.rb
rley-0.3.07 lib/rley/gfg/vertex.rb