Class: Panini::DerivationStrategy::Leftmost
- Defined in:
- lib/derivation_strategy/leftmost.rb
Overview
The Leftmost strategy is a naive strategy for deriving sentences from a grammar. It will aways substitute for the leftmost nonterminal first. If a nonterminal has more than one production, they will be chosen in a round-robin ordering.
This implementation is slow and will not work on many grammars.
In other words, don’t use this! It’s in place because it is simple to and was used for early testing.
Instance Method Summary collapse
-
#initialize(grammar) ⇒ Leftmost
constructor
A new instance of Leftmost.
-
#sentence ⇒ Object
Generates a sentence.
Constructor Details
#initialize(grammar) ⇒ Leftmost
Returns a new instance of Leftmost.
30 31 32 33 |
# File 'lib/derivation_strategy/leftmost.rb', line 30 def initialize(grammar) build_production_proxies(grammar) super(grammar) end |
Instance Method Details
#sentence ⇒ Object
Generates a sentence.
44 45 46 47 48 49 50 |
# File 'lib/derivation_strategy/leftmost.rb', line 44 def sentence derived_sentence, substituted = [@grammar.start], false begin derived_sentence, substituted = substitution_pass(derived_sentence) end while substituted derived_sentence end |