@fauton/cfg
Version:
A package to work with context free grammars and LL1 parsers
24 lines (23 loc) • 954 B
TypeScript
import { IContextFreeGrammar } from './types';
interface CykTableCellCombination<Type extends Set<string> | Array<string>> {
parts: [Type?, Type?];
merged: Type;
}
declare type CykTableDetailed<Type extends Set<string> | Array<string>> = Array<Array<{
combinations: CykTableCellCombination<Type>[];
value: Type;
}>>;
/**
* Parses a sentence given a cfg
* @param cfg Input cfg production rules and start variable
* @param sentenceTokens An array of sentence tokens
* @returns Boolean value on whether the sentence is part of the grammar and steps that the CYK algo took to resolve it
*/
export declare function cykParse(cfg: Pick<IContextFreeGrammar, 'productionRules' | 'startVariable'>, sentenceTokens: string[]): {
verdict: boolean;
cykTableDetailed: CykTableDetailed<string[]>;
cykTable: string[][];
nodeVariablesRecord: Record<string, string[]>;
sentenceTokens: string[];
};
export {};