Parser

public protocol Parser

A parser which can check if a word is in a language and generate a syntax tree explaining how a word was derived from a grammar

  • Creates a syntax tree which explains how a word was derived from a grammar

    Throws

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

    Declaration

    Swift

    func syntaxTree(for string: String) throws -> ParseTree

    Parameters

    string

    Input word, for which a parse tree should be generated

    Return Value

    A syntax tree explaining how the grammar can be used to derive the word described by the given tokenization

  • recognizes(_:) Extension method

    Returns true if the recognized language contains the given tokenization.

    Declaration

    Swift

    func recognizes(_ string: String) -> Bool

    Parameters

    string

    Word for which membership to the recognized grammar should be decided.

    Return Value

    True, if the word is generated by the grammar, false if not.