Sha256: 0951c7d9cf9db78512968b3887a98f7d08febfd3aafe75c4ebb8cc7d875bbdf6

Contents?: true

Size: 1.16 KB

Versions: 4

Compression:

Stored size: 1.16 KB

Contents

# frozen_string_literal: true

module Rley # This module is used as a namespace
  module Syntax # This module is used as a namespace
    # Abstract class for grammar symbols.
    # A grammar symbol is an element that appears in grammar rules.
    class GrmSymbol
      # The name of the grammar symbol
      attr_reader(:name)

      # An indicator that tells whether the grammar symbol can generate a
      # non-empty string of terminals.
      attr_writer(:generative)

      # Constructor.
      # aName [String] The name of the grammar symbol.
      def initialize(aName)
        raise 'Internal error: nil name encountered' if aName.nil?

        @name = aName.dup
        @name.freeze
      end

      # The String representation of the grammar symbol
      # @return [String]
      def to_s()
        return name.to_s
      end

      # @return [Boolean] true iff the symbol is a terminal
      def terminal?()
        # Default implementation to override if necessary
        return false
      end

      # @return [Boolean] true iff the symbol is generative.
      def generative?()
        return @generative
      end
    end # class
  end # module
end # module

# End of file

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rley-0.7.07 lib/rley/syntax/grm_symbol.rb
rley-0.7.06 lib/rley/syntax/grm_symbol.rb
rley-0.7.05 lib/rley/syntax/grm_symbol.rb
rley-0.7.04 lib/rley/syntax/grm_symbol.rb