Compiles context-free grammars into a dense indexed form and provides the grammar cleanups, normal forms and analyses of the class. The parsing, pushdown, rewriting and procedure packages build on it.
Algorithms
Reduction. Removes the variables that are unproductive or unreachable. (Cfg.reduce)
Unit rule elimination. Replaces unit productions by the productions they lead to. (Cfg.removeUnitRules)
Grammar stages. Eliminates left recursion, factors common prefixes and removes epsilon productions while retaining the empty word at a fresh protected start. (Cfg.eliminateLeftRecursion, Cfg.leftFactor, Cfg.removeEpsilon)
Chomsky normal form. Converts a grammar to binary and terminal productions with a protected start, and traces each step. (Cfg.toCnf, Cfg.traceCnf, Cfg.asCnf)
Greibach normal form. Converts a grammar so that every production starts with a terminal. (Cfg.toGnf, Cfg.asGnf)
FIRST, FOLLOW and LL(1) analysis. Computes nullable variables, the FIRST and FOLLOW sets, the number of distinct predictive entries and the LL(1) table with its conflicts. (Cfg.analyze, CfgAnalysis.ll1EntryCount)
Canonical LR(1). Builds closed item sets, transitions, action cells and conflicts for parsing and deterministic pushdown construction, and prints the complete table as stable text. The parsing package exports the same builder, dump and types. (buildLr1, dumpLr1, Lr1Automaton, Lr1ActionKind)
Finiteness analysis. Decides whether the language is empty, finite or infinite and gives exact bigint bounds on word length. (Cfg.analyzeFiniteness)
Shortest derivation. Finds the minimum word length and a word of that length. (Cfg.shortestLength, Cfg.shortestWord)
Finite language enumeration. Lists every word of a language that the analysis shows to be finite. (Cfg.enumerateFiniteLanguage)
Grammar dump. Prints a compiled grammar as stable declaration and production rows. (Cfg.dump)
Checked indices. Check a position against one grammar before giving it the role of a terminal or a production. (Cfg.terminalIndexAt, Cfg.productionIndexAt)
Data structures
Compiled grammar. Numbers the variables and terminals densely and keeps each production in declaration order. (Cfg, Cfg.compile, Cfg.decompile)
LR(1) construction data. Shares the source analyses, item interner, item and symbol ordering, state data and action construction with parsing. (Lr1Source, Lr1Items, compareItems, compareSymbols, StateData, stateActions)
Grammar builder. Collects the declarations of a grammar before it is compiled. (CfgBuilder)
Normal form brands. Mark a grammar as reduced, unit-free, in Chomsky normal form or in Greibach normal form. (ReducedCfg, UnitFreeCfg, CnfCfg, GnfCfg)
Role-specific indices. Distinct number types for variables, terminals and productions. (VariableIndex, TerminalIndex, ProductionIndex)
Symbol codes. Encode a variable as a nonnegative code and a terminal as a negative one, and decode them again. (CfgSymbol, variableSymbol, terminalSymbol, symbolIsVariable, symbolVariable, symbolTerminal)
Analysis and finiteness reports. The results of the FIRST, FOLLOW and finiteness analyses. (CfgAnalysis, Finiteness)
Grammar parts. The variables of a compiled grammar, the words over its terminals and the copy of one right-hand side. (CfgVariable, TerminalWord, Cfg.rhsOf)
Decoders. Read the analysis, the conflicts, the symbols and the indices back from plain data. (cfgAnalysisDecoder, ll1ConflictDecoder, cfgSymbolDecoder, productionIndexDecoder, terminalIndexDecoder)
Enumerations. Name the closed sets of strings that the types and the wire data of the package use. (CnfStepKind, FinitenessKind, FormIssueCode, VariableRole)