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.

    • Method Detail

      • getVersion

        public java.lang.String getVersion()
        Get the version of this grammar.
        Overrides:
        getVersion in class Grammar
        Returns:
        the version.
      • setVersion

        public void setVersion​(java.lang.String version)
        Set the version of this grammar.
        Overrides:
        setVersion in class Grammar
        Parameters:
        version - the version.
      • isUsesRegex

        public boolean isUsesRegex()
        Does this parser use regular expressions?
        Returns:
        true if it does.
      • getParserType

        public ParserType getParserType()
        The parser type of this parser.
        Returns:
        The parser type.
      • getSeed

        public NonterminalSymbol getSeed()
        The seed of this parser.
        Returns:
        the seed.
      • getParserOptions

        public ParserOptions getParserOptions()
        The parser options of this parser.
        Returns:
        the options.
      • 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)
        Get the follow set for the specified symbol.
        Parameters:
        symbol - The symbol.
        Returns:
        The follow set.