Class ParserGrammar


  • public class ParserGrammar
    extends Grammar
    A grammar for the parser.

    A grammar is a list of rules. Each rule defines a non-terminal symbol as a sequence of zero or more symbols (terminal or nonterminal).

    A grammar can be used to create a parser for that grammar. The ParserGrammar is derived from a SourceGrammar. The ParserGrammar is immutable.

    • Field Detail

      • usesRegex

        public final boolean usesRegex
    • Method Detail

      • getParser

        public GearleyParser getParser()
        Get a parser for this grammar.

        Returns a parser that will parse an input against the rules that define this grammar.

        Returns:
        the parser
      • isNullable

        public boolean isNullable​(Symbol symbol)
        Is a symbol nullable?
        Specified by:
        isNullable in class Grammar
        Parameters:
        symbol - the symbol
        Returns:
        true if the symbol is nullable
        Throws:
        java.lang.UnsupportedOperationException - if the grammar is open
      • getHygieneReport

        public HygieneReport getHygieneReport()
        Get a hygiene report for this compiled grammar.
        Returns:
        the report.
      • getFirst

        public java.util.Set<Symbol> getFirst​(Symbol symbol)
        Return the set of "first" symbols for the specified symbol

        The first symbols of a nonterminal are all those symbols that can appear "first" in a matching parse for that nonterminal. The first set of a terminal symbol is just the symbol itself.

        Parameters:
        symbol - the symbol of interest
        Returns:
        the first set for the symbol
      • getFollow

        public java.util.Set<Symbol> getFollow​(Symbol symbol)