Class: Rley::Syntax::Production
- Inherits:
-
Object
- Object
- Rley::Syntax::Production
- Defined in:
- lib/rley/syntax/production.rb
Overview
In a context-free grammar, a production is a rule in which its left-hand side (LHS) consists solely of a non-terminal symbol and the right-hand side (RHS) consists of a sequence of symbols. The symbols in RHS can be either terminal or non-terminal symbols. The rule stipulates that the LHS is equivalent to the RHS, in other words every occurrence of the LHS can be substituted to corresponding RHS.
Instance Attribute Summary collapse
-
#lhs ⇒ Object
(also: #head)
readonly
The left-hand side of the rule.
-
#rhs ⇒ Object
(also: #body)
readonly
The right-hand side (rhs) consists of a sequence of grammar symbols.
Instance Method Summary collapse
-
#empty? ⇒ Boolean
Is the rhs empty? @ return true if the rhs has no members.
-
#initialize(aNonTerminal, theSymbols) ⇒ Production
constructor
A new instance of Production.
Constructor Details
#initialize(aNonTerminal, theSymbols) ⇒ Production
Returns a new instance of Production.
24 25 26 27 |
# File 'lib/rley/syntax/production.rb', line 24 def initialize(aNonTerminal, theSymbols) @lhs = valid_lhs(aNonTerminal) @rhs = SymbolSeq.new(theSymbols) end |
Instance Attribute Details
#lhs ⇒ Object (readonly) Also known as: head
The left-hand side of the rule. It must be a non-terminal symbol
17 18 19 |
# File 'lib/rley/syntax/production.rb', line 17 def lhs @lhs end |
#rhs ⇒ Object (readonly) Also known as: body
The right-hand side (rhs) consists of a sequence of grammar symbols
14 15 16 |
# File 'lib/rley/syntax/production.rb', line 14 def rhs @rhs end |
Instance Method Details
#empty? ⇒ Boolean
Is the rhs empty? @ return true if the rhs has no members.
31 32 33 |
# File 'lib/rley/syntax/production.rb', line 31 def empty?() return rhs.empty? end |