Class: Dhaka::GrammarSymbol

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

Overview

Each grammar symbol is uniquely identified by a string name. The name of a symbol can be anything (except the two reserved names '_Start_' and '_End_') and need not correspond to its character representation. For example, an ampersand in the input string could be tokenized as a symbol with a name ‘AND_OP’. You never have to directly instantiate a GrammarSymbol. It is done implicitly for you when you define a Grammar.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ GrammarSymbol

Returns a new instance of GrammarSymbol.



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

def initialize(name)
  @name = name
end

Instance Attribute Details

#associativityObject

Returns the value of attribute associativity.



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

def associativity
  @associativity
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#non_terminalObject

Returns the value of attribute non_terminal.



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

def non_terminal
  @non_terminal
end

#nullableObject

Returns the value of attribute nullable.



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

def nullable
  @nullable
end

#precedenceObject

Returns the value of attribute precedence.



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

def precedence
  @precedence
end

Instance Method Details

#<=>(other) ⇒ Object



23
24
25
# File 'lib/dhaka/grammar/grammar_symbol.rb', line 23

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

#terminalObject



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

def terminal
  !non_terminal
end

#to_sObject

:nodoc:



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

def to_s #:nodoc:
  name.dup
end