Class GllParser

  • All Implemented Interfaces:
    GearleyParser

    public class GllParser
    extends java.lang.Object
    implements GearleyParser
    The GLL parser.

    The GLL parser compares an input sequence against a grammar and determines if the input is a sentence in the grammar.

    This is an attempt to implement the work described in Derivation representation using binary subtree sets by Elizabeth Scott, Adrian Johnstone, and L. Thomas van Binsbergen. It returns the SPPF style forest derived from the binary subtrees. (There's some aspect of the description of how to extract trees directly from the BSR that I cannot grok.)

    • Field Detail

      • logcategory

        public static final java.lang.String logcategory
        The logging category for log messages about the GLL parser.
        See Also:
        Constant Field Values
      • gllexecution

        public static final java.lang.String gllexecution
        The logging category for the log messages about the execution of the GLL parser.
        See Also:
        Constant Field Values
    • Constructor Detail

      • GllParser

        public GllParser​(ParserGrammar grammar,
                         ParserOptions options)
        Construct a GLL parser.
        Parameters:
        grammar - the grammar.
        options - the options.
    • Method Detail

      • parse

        public GllResult parse​(Token[] input)
        Description copied from interface: GearleyParser
        Parse an array of tokens.

        Note that the GLL parser only parses character tokens.

        Specified by:
        parse in interface GearleyParser
        Parameters:
        input - The array of tokens.
        Returns:
        The parse result.
      • parse

        public GllResult parse​(java.util.Iterator<Token> input)
        Description copied from interface: GearleyParser
        Parse a sequence of tokens provided by an iterator.

        Note that the GLL parser only parses character tokens.

        Specified by:
        parse in interface GearleyParser
        Parameters:
        input - The token iterator.
        Returns:
        The parse result.
      • parse

        public GllResult parse​(java.lang.String input)
        Description copied from interface: GearleyParser
        Parse a string.
        Specified by:
        parse in interface GearleyParser
        Parameters:
        input - The input string.
        Returns:
        The parse result.
      • succeeded

        public boolean succeeded()
        Did the parse succeed?

        Is the parse finished and did it find at least one parse?

        Returns:
        true if it did.
      • getTokens

        public Token[] getTokens()
        Return the tokens used in the parse.
        Returns:
        the tokens.
      • getPriorityStyle

        public java.lang.String getPriorityStyle()
        Description copied from interface: GearleyParser
        The priority style.

        Meaningless if priorities are not used in the grammar.

        Specified by:
        getPriorityStyle in interface GearleyParser
        Returns:
        The priority style.
      • getDefaultPriority

        public int getDefaultPriority()
        Description copied from interface: GearleyParser
        The default priority.

        Meaningless if priorities are not used in the grammar.

        Specified by:
        getDefaultPriority in interface GearleyParser
        Returns:
        The default priority.
      • hasMoreInput

        public boolean hasMoreInput()
        Description copied from interface: GearleyParser
        Returns true of the parse ended without consuming all input.
        Specified by:
        hasMoreInput in interface GearleyParser
        Returns:
        true if there was more input.
      • getOffset

        public int getOffset()
        Description copied from interface: GearleyParser
        Returns the last offset read by the parser.
        Specified by:
        getOffset in interface GearleyParser
        Returns:
        the offset.
      • getLineNumber

        public int getLineNumber()
        Description copied from interface: GearleyParser
        Returns the line number of the last line read by the parser.
        Specified by:
        getLineNumber in interface GearleyParser
        Returns:
        the line number.
      • getColumnNumber

        public int getColumnNumber()
        Description copied from interface: GearleyParser
        Returns the column number of the last character on the last line read by the parser.
        Specified by:
        getColumnNumber in interface GearleyParser
        Returns:
        the column number.