type Position = { line: number; column: number; }; type Tocken = { tocken: Terminal; origin: string; position?: Position; Options?: Array; }; type NonTerminal = string; type Terminal = string; type Grammer = { nonTerminal: NonTerminal; derivations: Array>; }; type GrammerSetLine = { tocken: NonTerminal | Terminal; terminals: Set; isTerminal?: boolean; }; type GrammerSet = Array; type PredictLine = { nonTerminal: string; terminal2Derivation: Map | Record; }; type PredictTable = Array; type PredictProcessLine = { parseStack: Array; remainingInput: string; parseAction: string; }; type Rule = Array; type Process = { ruleIndex: number; result: T; }; type LRStateNodeItem = { nonTerminal: NonTerminal; derivation: string[]; matchPoint: number; lookAheadTocken?: string[]; }; /** * 包含四个属性,id表示状态机的id,item表示状态机中的项目,还有edge类似指针,第四个属性是可选的 */ type LRStateNode = { id: number; items: LRStateNodeItem[]; edges: { tocken: NonTerminal | Terminal; next: LRStateNode; }[]; acc?: boolean; }; type LRStateNodeForShow = { id: number; items: string[]; edges: { tocken: NonTerminal | Terminal; next: LRStateNodeForShow; }[]; isCollision: boolean; acc?: boolean; }; type LRPredictTableLine = { id: number; action: Map; goto: Map; }; type LRPredictTable = Array; type LRPredictLine = { stack: number[]; symbols: string[]; input: string[]; move?: string; }; type LRPredictResultTable = Array; type LRPredictLineWithAST = { stack: number[]; symbols: LRASTNode[]; input: string[]; move?: string; }; type LRPredictResultTableWithASTNode = Array; type LRASTNode = { id: any; text: string; check?: boolean; children?: LRASTNode[]; }; declare class Lexer { nonTerminals: Array; terminals: Array<[string, RegExp]>; currentLine: number; currentColumn: number; source: string; constructor(terminals: Array<[string, RegExp]>, nonTerminals: Array); setSource(source: string): void; getSource(): void; remainString(): string; next(): Tocken; pop(): Tocken; nextNotEmptyTerminal(): Tocken; nextNotEmpty(step: number): Tocken; popNotEmptyTerminal(): Tocken; isTerminal(str: string): boolean; splitDerivation(str: string): Array; getNewNonTerminal(nonTerminal: string): string; } declare class LL1Parser { lexer: Lexer; textGrammers: Array; constructor(terminals: Array<[string, RegExp]>, nonTerminals: Array, inGrammers: Array); getFirstSet(): GrammerSet; getFollowSet(firstSet?: GrammerSet): GrammerSet; getPredictTable(firstSet?: GrammerSet, followSet?: GrammerSet): PredictTable; getPredictProcess(input: string, parseStartNonTerminal: string, predictTable?: PredictTable): Array; checkPredickTableIsValid(predictTable: PredictTable): boolean; checkIsLL0(): boolean; getFirstSetProgressive(): IterableIterator>; getFollowSetProgressive(firstSet?: GrammerSet): IterableIterator>; getPredictProcessProgressive(input: string, parseStartNonTerminal: string, predictTable?: PredictTable): IterableIterator>; getPredictTableProgressive(firstSet?: GrammerSet, followSet?: GrammerSet): IterableIterator>; } declare function getTockFromSimpleGrammers(inGrammers: Array): { nonTerminals: Array; terminals: Array<[string, RegExp]>; }; declare function checkNeedunionGrammers(grammers: Array): boolean; declare function unionGrammers(grammers: Array, nonTerminals?: Array, terminals?: Array<[string, RegExp]>): Array; declare function checkNeedliftUpCommonTocken(grammers: Array, nonTerminals?: Array, terminals?: Array<[string, RegExp]>): boolean; declare function liftUpCommonTocken(grammers: Array, nonTerminals?: Array, terminals?: Array<[string, RegExp]>): Array; declare function checkNeedClearRightRecursion(grammers: Array, nonTerminals?: Array, terminals?: Array<[string, RegExp]>): boolean; declare function clearRightRecursion(grammers: Array, nonTerminals?: Array, terminals?: Array<[string, RegExp]>): Array; declare class LRParser { initialStateNode: LRStateNode | null; allStateNodesMap?: Map; lexer?: Lexer; grammers?: string[]; constructor(); generateState(grammers: string[], parseStartNonTerminal: string, nonTerminals?: Array, terminals?: Array<[string, RegExp]>): void; generateStateProgressive(grammers: string[], parseStartNonTerminal: string, nonTerminals?: Array, terminals?: Array<[string, RegExp]>): IterableIterator; predictInput(input: string, predictTable: LRPredictTable): LRPredictResultTable; predictInputWithAST(input: string, predictTable: LRPredictTable): LRPredictResultTableWithASTNode; predictInputProgressive(input: string, predictTable: LRPredictTable): IterableIterator; generateLR0PredictTable(): LRPredictTable; generateSLR1PredictTable(): LRPredictTable; get stateGraph(): LRStateNodeForShow; } declare class LR1Parser { initialStateNode: LRStateNode | null; allStateNodesMap?: Map; lexer?: Lexer; grammers?: string[]; firstSet?: GrammerSet; constructor(); generateState(grammers: string[], parseStartNonTerminal: string, nonTerminals?: Array, terminals?: Array<[string, RegExp]>): void; predictInput(input: string, predictTable: LRPredictTable): LRPredictResultTable; mergeNewNode(node: LRStateNode, addNode: LRStateNode): void; generateLALRPredictTable(): LRPredictTable; generateLR1PredictTable(): LRPredictTable; get stateGraph(): LRStateNodeForShow; } export { LL1Parser, LR1Parser, LRParser, Lexer, checkNeedClearRightRecursion, checkNeedliftUpCommonTocken, checkNeedunionGrammers, clearRightRecursion, getTockFromSimpleGrammers, liftUpCommonTocken, unionGrammers };