Class ParseForest

  • Direct Known Subclasses:
    ParseForestGLL

    public class ParseForest
    extends java.lang.Object
    An SPPF is a shared packed parse forest.

    The SPPF is a graph representation of all the (possibly infinite) parses that can be used to recognize the input sequence as a sentence in the grammar.

    • Constructor Detail

    • Method Detail

      • isAmbiguous

        public boolean isAmbiguous()
        Is the grammar represented by this graph ambiguous?

        A grammar is ambiguous if there are more than two parses that will recognize the input.

        Returns:
        true if the grammar is ambiguous
      • isInfinitelyAmbiguous

        public boolean isInfinitelyAmbiguous()
        Is the grammar represented by this graph infinitely ambiguous?

        If the answer is "true", then the graph is infinitely ambiguous. If the graph is ambiguous and the anwer is "false", then all that can be said is the single parse explored to check ambiguity did not encounter infinite ambiguity. It is not an assertion that no unexplored part of the graph contains a loop.

        Returns:
        true if the parse forest is known to be infinitely ambiguous
      • getParseTreeCount

        public int getParseTreeCount()
        How many parse trees are there in this forest?

        In an infinitely ambiguous graph, there are an infinite number of parse trees. However, CoffeeGrinder will never follow the same edge twice when constructing a tree, it won't loop. So the number of available trees is always a finite number.

        Returns:
        the parse tree count
      • getAmbiguousNodes

        public java.util.List<ForestNode> getAmbiguousNodes()
      • size

        public int size()
        How big is the graph?
        Returns:
        the number of nodes in the graph
      • getNodes

        public java.util.List<ForestNode> getNodes()
        Get the nodes in the graph.
        Returns:
        the nodes in the graph.
      • getOptions

        public ParserOptions getOptions()
        Get the options for this forest.
        Returns:
        the options.
      • serialize

        public java.lang.String serialize()
        Serialize the graph as XML.
        Returns:
        an XML serialization as a string
      • serialize

        public void serialize​(java.io.PrintStream stream)
        Serialize the graph as XML.
        Parameters:
        stream - the stream on which to write the XML serialization
      • serialize

        public void serialize​(java.lang.String filename)
        Serialize the graph as XML.

        This method attempts to write the XML to a file.

        Parameters:
        filename - the name of the file
        Throws:
        ForestException - if a error occurs attempt to write to the file