Class Grammar

java.lang.Object
org.nineml.coffeegrinder.parser.Grammar
Direct Known Subclasses:
ParserGrammar, SourceGrammar

public abstract class Grammar extends Object
The grammar representation.

This is an abstract class with two implementations: SourceGrammar and ParserGrammar. The source grammar can be updated, the parser grammar is immutable.

  • Field Details

  • Constructor Details

    • Grammar

      public Grammar()
  • Method Details

    • getRules

      public List<Rule> getRules()
      Get the rules currently defined in this grammar.

      For a ParserGrammar, this is the final set.

      Returns:
      Returns the rules that define the grammar.
    • getSymbols

      public Set<NonterminalSymbol> getSymbols()
      Get the currently defined nonterminals in the grammar.

      For a ParserGrammar, this is the final set.

      Returns:
      the set of nonterminals.
    • getRulesBySymbol

      public Map<NonterminalSymbol,List<Rule>> getRulesBySymbol()
      Get the rules currently defined in this grammar organized by symbol.

      For a ParserGrammar, this is the final set.

      Returns:
      Returns the rules that define the grammar.
    • getRulesForSymbol

      public List<Rule> getRulesForSymbol(NonterminalSymbol symbol)
      Get the rules currently defined in this grammar for a particular symbol.

      For a ParserGrammar, this is the final set.

      Parameters:
      symbol - The symbol.
      Returns:
      Returns the rules that define the grammar.
    • getMetadataProperty

      public String getMetadataProperty(String name)
      Gets a metadata property.

      Metadata properties exist solely for annotations by an application.

      Parameters:
      name - the name of the property
      Returns:
      the value of the property, or null if no such property exists
      Throws:
      NullPointerException - if the name is null
    • getMetadataProperies

      public Map<String,String> getMetadataProperies()
      Gets the metadata properties.

      Metadata properties exist solely for annotations by an application.

      Returns:
      the metadata properties
    • isNullable

      public abstract boolean isNullable(Symbol symbol)
      Is the symbol nullable?

      A TerminalSymbol is never nullable.

      For a ParserGrammar, the answer is definitive. For an SourceGrammar, a symbol that isn't currently nullable could become nullable by the addition of more rules.

      Parameters:
      symbol - The symbol.
      Returns:
      true if the symbol is nullable