TOC Toolkit API - v0.1.0
    Preparing search index...

    toc-toolkit/grammars/parsing

    Recognizes and parses words of a context-free grammar, and counts and samples their derivations. The procedure packages and the app use it for membership, ambiguity and language slices.

    • Original tree counts. Keeps separate production occurrences, counts nullable multiplicities, expands each erased occurrence and removes weighted acyclic unit paths to form proper polynomial equations. Exact convolutions compute counts through a supplied inclusive horizon. (countingSystem, countingCoefficients, countingHorizon)

    • CYK. Recognizes a word with a grammar in Chomsky normal form by dynamic programming over spans. (recognizeCyk)

    • Earley parsing. Parses with any context-free grammar and builds a packed parse forest, with a trace of the chart items. (parseEarley)

    • Prepared Earley recognizer. Reuses one grammar for many queries, with Leo compression of completion chains, FIRST-based lookahead filtering and a cache of dead prefixes. Preparation charges the supplied budget and returns exhaustion when the budget stops compilation. (prepareRecognizer)

    • Smallest trees. Extracts the smallest parse trees from a forest. (smallestTrees)

    • Words by length. Computes all words of one length by a recurrence over a grammar in Chomsky normal form, and keeps the words of every variable at every completed length, which variableWords returns and completed counts. (WordTable)

    • Language slices. Completes the words of every length up to a bound. (languageSlice)

    • Deterministic language witnesses. Tests LL(1), SLR(1), LALR(1) and canonical LR(1) in order and returns the first sufficient property. A result of not-shown makes no claim about the language. (deterministicWitness, DeterministicWitness)

    • Canonical LR(1). Exports the context-free owner's LR(1) builder and types, keeping the parsing API for automata, action tables and conflicts. (buildLr1)

    • Bounded lookahead. Builds LL(k) prediction tables and canonical LR(k) closures and tables for k from 1 to 3. LL predictions retain their reachable right contexts, and LookaheadEnd.End marks the end of input in a lookahead. parsingClass finds the smallest k for each method within that bound, or returns ParsingClassStatus.Unknown. (llkTable, lrkClosure, lrkTable, parsingClass)

    • SLR(1) and LALR(1) tables. Build the LR(0) automaton, which has one state for each core, and attach reductions by FOLLOW sets (SLR) or by lookaheads that propagate to a fixed point (LALR). Every conflicting cell stays in the table. (buildLrTable, LrTableKind)

    • Conflict explanations. Name, for each conflict, a shortest symbol prefix that leads into the state, the lookahead and the item that calls for each competing action, and write it as text. A shift item and a reduce item on one prefix are two readings of the same input. The explanation does not decide ambiguity, and the ambiguity procedures supply the word with two trees. (explainConflicts, describeConflict, LrConflictExplanation)

    • Unifying conflicts. Searches pairs of parser stacks after forcing competing actions and returns two trees when both accept one word. The search examines at most 20,000 configurations and words of at most 8 terminals, and charges the supplied budget. A search that reaches a budget limit returns exhaustion and leaves the conflict explanations available. (unifyConflict)

    • Derivation counting. Counts the derivation trees of each variable by yield length with exact integers. (countDerivations)

    • Derivation sampling. Draws derivation trees uniformly from the counts with a seeded generator. sampleFromCounts draws from a count table that an earlier call built, so a caller that samples many lengths counts once. (sampleDerivations, sampleFromCounts)

    • Terminal words. Reads a word against a grammar and stops at its first foreign symbol. (terminalWord)

    • Dumps. Print a tree, a forest, a language slice or an LR(1) automaton as text. (dumpTree, dumpForest, dumpSlice, dumpLr1)

    • Algebraic counting system. Holds weighted zero-constant equations, the original degree bound and the separate empty-word count. The input records every original production occurrence. (CountingGrammar, CountingRule, CountingSystem, CountingTerm, dumpCountingSystem)

    • Parse tree. A tree of variable nodes and terminal leaves with its yield. (ParseTree, treeYield)

    • Packed parse forest. Shares terminal, symbol and intermediate nodes so that ambiguous parses stay compact. (ParseForest)

    • Word table. Stores the words of each length for a grammar. (WordTable)

    • LR(1) automaton. Holds the item sets, transitions and action cells. (Lr1Automaton)

    • Language slice. The complete language at one token length, as a list of words. (LanguageSlice, SliceIssue)

    • Derivation counts. The exact number of derivation trees of each variable by yield length. (DerivationCounts)

    • Sample request. The yield length, the sample count and the seed of one draw from a count table. (SampleRequest)

    • Earley run. The packed forest of one parse with its chart frames. (EarleyRun, EarleyFrame)

    • Prepared recognizer. One compiled grammar that answers many queries, shared within a budget root under a named artifact key. (PreparedRecognizer, preparedRecognizer, RECOGNIZER_ARTIFACT)

    • Decoders. Read a forest and an Earley frame back from plain data. (parseForestDecoder, earleyFrameDecoder)

    • Enumerations. Name the closed sets of strings that the types and the wire data of the package use. (ForestNodeKind, Lr1ActionKind, SliceIssueCode, TreeNodeKind)

    • Constants. Fix the limits and tables that the package exports. (MAX_TREE_COUNT)