Sha256: df1e124c48bc82cd5487d9d6afe2fefc21566b0fd7ea9ba1749808391f88dfdd

Contents?: true

Size: 702 Bytes

Versions: 3

Compression:

Stored size: 702 Bytes

Contents

module Panini


  # The Grammar stores the start symbol and nonterminals.
  class Grammar
    
    def initialize
      @nonterminals = []
    end

    # Returns the grammar's start symbol. This will be the first
    # nonterminal added to the grammar if it hasn't been specified.
    def start
      @start ||= @nonterminals[0]
    end

    def start=(start)
      @start = start
    end

    # Add a nonterminal to the grammar.
    def add_nonterminal(name = nil)
      Panini::Nonterminal.new(name).tap do |new_nonterminal|
        @nonterminals << new_nonterminal
      end
    end

    # The list of nonterminals in the grammar.
    def nonterminals
      @nonterminals.dup
    end
    
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
panini-1.3.0 lib/grammar.rb
panini-1.2.0 lib/grammar.rb
panini-1.1.1 lib/grammar.rb