Class: Panini::Grammar
- Inherits:
-
Object
- Object
- Panini::Grammar
- Defined in:
- lib/grammar.rb
Overview
The Grammar stores the start symbol and nonterminals.
Instance Method Summary collapse
-
#add_nonterminal(name = nil) ⇒ Object
Add a nonterminal to the grammar.
-
#initialize ⇒ Grammar
constructor
A new instance of Grammar.
-
#nonterminals ⇒ Object
The list of nonterminals in the grammar.
-
#start ⇒ Object
Returns the grammar’s start symbol.
- #start=(start) ⇒ Object
Constructor Details
#initialize ⇒ Grammar
Returns a new instance of Grammar.
7 8 9 |
# File 'lib/grammar.rb', line 7 def initialize @nonterminals = [] end |
Instance Method Details
#add_nonterminal(name = nil) ⇒ Object
Add a nonterminal to the grammar.
22 23 24 25 26 |
# File 'lib/grammar.rb', line 22 def add_nonterminal(name = nil) Panini::Nonterminal.new(name).tap do |new_nonterminal| @nonterminals << new_nonterminal end end |
#nonterminals ⇒ Object
The list of nonterminals in the grammar.
29 30 31 |
# File 'lib/grammar.rb', line 29 def nonterminals @nonterminals.dup end |
#start ⇒ Object
Returns the grammar’s start symbol. This will be the first nonterminal added to the grammar if it hasn’t been specified.
13 14 15 |
# File 'lib/grammar.rb', line 13 def start @start ||= @nonterminals[0] end |
#start=(start) ⇒ Object
17 18 19 |
# File 'lib/grammar.rb', line 17 def start=(start) @start = start end |