Class: Dhaka::Production
- Inherits:
-
Object
- Object
- Dhaka::Production
- Defined in:
- lib/grammar/production.rb
Instance Attribute Summary collapse
-
#expansion ⇒ Object
readonly
Returns the value of attribute expansion.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#symbol ⇒ Object
readonly
Returns the value of attribute symbol.
Instance Method Summary collapse
-
#initialize(symbol, expansion, name, precedence = nil) ⇒ Production
constructor
A new instance of Production.
- #precedence ⇒ Object
-
#to_s ⇒ Object
:nodoc:.
Constructor Details
#initialize(symbol, expansion, name, precedence = nil) ⇒ Production
Returns a new instance of Production.
7 8 9 10 11 12 |
# File 'lib/grammar/production.rb', line 7 def initialize(symbol, expansion, name, precedence = nil) @symbol = symbol @expansion = expansion @name = name @precedence = precedence end |
Instance Attribute Details
#expansion ⇒ Object (readonly)
Returns the value of attribute expansion.
5 6 7 |
# File 'lib/grammar/production.rb', line 5 def expansion @expansion end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/grammar/production.rb', line 5 def name @name end |
#symbol ⇒ Object (readonly)
Returns the value of attribute symbol.
5 6 7 |
# File 'lib/grammar/production.rb', line 5 def symbol @symbol end |
Instance Method Details
#precedence ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/grammar/production.rb', line 14 def precedence unless @precedence @expansion.reverse_each do |symbol| if symbol.terminal @precedence = symbol.precedence break end end end @precedence end |
#to_s ⇒ Object
:nodoc:
26 27 28 |
# File 'lib/grammar/production.rb', line 26 def to_s #:nodoc: "#{@name} #{@symbol} ::= #{@expansion.join(' ')}" end |