Class: Rley::Syntax::GrmSymbol

Inherits:
Object
  • Object
show all
Defined in:
lib/rley/syntax/grm_symbol.rb

Overview

Abstract class for grammar symbols. A grammar symbol is an element that appears in grammar rules.

Direct Known Subclasses

NonTerminal, Terminal

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(aName) ⇒ GrmSymbol

Constructor. aName [String] The name of the grammar symbol.



15
16
17
18
19
# File 'lib/rley/syntax/grm_symbol.rb', line 15

def initialize(aName)
  raise 'Internal error: nil name encountered' if aName.nil?
  @name = aName.dup
  @name.freeze
end

Instance Attribute Details

#generative=(value) ⇒ Object (writeonly)

An indicator that tells whether the grammar symbol can generate a non-empty string of terminals.



11
12
13
# File 'lib/rley/syntax/grm_symbol.rb', line 11

def generative=(value)
  @generative = value
end

#nameObject (readonly)

The name of the grammar symbol



7
8
9
# File 'lib/rley/syntax/grm_symbol.rb', line 7

def name
  @name
end

Instance Method Details

#generative?Boolean



34
35
36
# File 'lib/rley/syntax/grm_symbol.rb', line 34

def generative?()
  return @generative
end

#terminal?Boolean



28
29
30
31
# File 'lib/rley/syntax/grm_symbol.rb', line 28

def terminal?()
  # Default implementation to override if necessary
  return false
end

#to_sString

The String representation of the grammar symbol



23
24
25
# File 'lib/rley/syntax/grm_symbol.rb', line 23

def to_s()
  return name.to_s
end