Class: Dhaka::GrammarSymbol

Inherits:
Object
  • Object
show all
Defined in:
lib/grammar/grammar_symbol.rb

Overview

Each grammar symbol is uniquely identified by a string name. The name of a symbol can be anything and need not correspond to its character representation. For example, an ampersand in the character stream could be tokenized as a symbol with a name ‘whatever’. In general, it’s best to choose symbol names that are descriptive.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ GrammarSymbol

Returns a new instance of GrammarSymbol.



10
11
12
# File 'lib/grammar/grammar_symbol.rb', line 10

def initialize(name)
  @name = name
end

Instance Attribute Details

#associativityObject

Returns the value of attribute associativity.



9
10
11
# File 'lib/grammar/grammar_symbol.rb', line 9

def associativity
  @associativity
end

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/grammar/grammar_symbol.rb', line 8

def name
  @name
end

#non_terminalObject

Returns the value of attribute non_terminal.



9
10
11
# File 'lib/grammar/grammar_symbol.rb', line 9

def non_terminal
  @non_terminal
end

#nullableObject

Returns the value of attribute nullable.



9
10
11
# File 'lib/grammar/grammar_symbol.rb', line 9

def nullable
  @nullable
end

#precedenceObject

Returns the value of attribute precedence.



9
10
11
# File 'lib/grammar/grammar_symbol.rb', line 9

def precedence
  @precedence
end

Instance Method Details

#<=>(other) ⇒ Object



19
20
21
# File 'lib/grammar/grammar_symbol.rb', line 19

def <=> other
  self.name <=> other.name
end

#terminalObject



13
14
15
# File 'lib/grammar/grammar_symbol.rb', line 13

def terminal
  !non_terminal
end

#to_sObject



16
17
18
# File 'lib/grammar/grammar_symbol.rb', line 16

def to_s
  name
end