Class: Dhaka::Production

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(symbol, expansion, name, precedence = nil) ⇒ Production

Returns a new instance of Production.



6
7
8
9
10
11
# File 'lib/grammar/production.rb', line 6

def initialize(symbol, expansion, name, precedence = nil)
  @symbol     = symbol
  @expansion  = expansion
  @name       = name
  @precedence = precedence
end

Instance Attribute Details

#expansionObject (readonly)

Returns the value of attribute expansion.



4
5
6
# File 'lib/grammar/production.rb', line 4

def expansion
  @expansion
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/grammar/production.rb', line 4

def name
  @name
end

#symbolObject (readonly)

Returns the value of attribute symbol.



4
5
6
# File 'lib/grammar/production.rb', line 4

def symbol
  @symbol
end

Instance Method Details

#precedenceObject



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/grammar/production.rb', line 13

def precedence
  unless @precedence
    expansion.reverse_each do |symbol|
      if symbol.terminal
        @precedence = symbol.precedence
        break
      end
    end 
  end
  @precedence
end

#to_sObject

:nodoc:



25
26
27
# File 'lib/grammar/production.rb', line 25

def to_s #:nodoc:
  "#{name} #{symbol} ::= #{expansion.join(' ')}"
end