class Panini::Grammar

The Grammar stores the start symbol and nonterminals.

Public Class Methods

new() click to toggle source
# File lib/grammar.rb, line 7
def initialize
  @nonterminals = []
end

Public Instance Methods

add_nonterminal(name = nil) click to toggle source

Add a nonterminal to the grammar.

# 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() click to toggle source

The list of nonterminals in the grammar.

# File lib/grammar.rb, line 29
def nonterminals
  @nonterminals.dup
end
start() click to toggle source

Returns the grammar's start symbol. This will be the first nonterminal added to the grammar if it hasn't been specified.

# File lib/grammar.rb, line 13
def start
  @start ||= @nonterminals[0]
end
start=(start) click to toggle source
# File lib/grammar.rb, line 17
def start=(start)
  @start = start
end