AmbiguousGrammarParser

public protocol AmbiguousGrammarParser : Parser

A parser that can parse ambiguous grammars and retrieve every possible syntax tree

  • Generates all syntax trees explaining how a word can be derived from a grammar.

    This function should only be used for ambiguous grammars and if it is necessary to retrieve all parse trees, as it comes with an additional cost in runtime.

    For unambiguous grammars, this function should return the same results as syntaxTree(for:).

    Throws

    A syntax error if the word is not in the language recognized by the parser

    Declaration

    Swift

    func allSyntaxTrees(for string: String) throws -> [ParseTree]

    Parameters

    string

    Input word, for which all parse trees should be generated

    Return Value

    All syntax trees which explain how the input was derived from the recognized grammar