Class: Panini::Grammar

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

Overview

The Grammar stores the start symbol and nonterminals.

Instance Method Summary collapse

Constructor Details

#initializeGrammar

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

#nonterminalsObject

The list of nonterminals in the grammar.



29
30
31
# File 'lib/grammar.rb', line 29

def nonterminals
  @nonterminals.dup
end

#startObject

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