import { LR1 } from './lr1'; import { LR1_Rule, LR1_RuleItem } from './lr1rule'; import { LR1_TableEntry } from './lr1table'; /** * Paring state (refer to LR(1) parsing textbooks). */ export declare class LR1_State { /** * index number of the state (labeling of the state graph; root-state has * index 0). */ private index; /** * CLOSURE_1 items of the state. ATTENTION: implemented as array; not as set. */ private itemSet; /** * reference to LR1 object */ private lr1; /** * outgoing edges of state transitions */ outEdges: LR1_Edge[]; /** * incoming edges of state transitions */ inEdges: LR1_Edge[]; constructor(lr1: LR1); setIndex(i: number): void; getIndex(): number; /** * Compares a given state to the current state object * @param s state to be compared with * @returns true, if the given state is equal th the current state object. */ equal(s: LR1_State): boolean; /** * Adds a new item if it is not yet present in the item set. * NOTE: items are said to be equal, if the rule and the current position are * equal. The lookahead set is updated such that the new lookahead-set is * constructed from the previous lookahead-set unified the lookahead-set of * the given item. * @param newItem The item to be added * @returns true, if the number of items increased; otherwise false */ addItem(newItem: LR1_StateItem): boolean; /** * Calculates CLOSURE_1 from an initial item set as follows: * Let a, b, c in (Sigma uu V)^* and let "." denote the current position. * For all items of the form [x -> a . y b, L], * with rule [x -> a . y b] and lookahead set L, * add all production rules [y -> . c, FIRST(bL)] to the closure. * If only FIRST(bL) is different to existing items, than modify the * existing item where only FIRST differs by L := L uu FIRST(bL). * Run this procedure until no more changes occur. * This method also calculates and returns transitions to other states. * For these states, only the initial CLOSURE_1 is drawn, s.t. a recursive * calls construct the set of all states. * Transitions are calculated as follows: Determine the set of outgoing * terminals (called "t") and the set of outgoing non-terminals (called "nt"). * These sets are constructed by the set of (non-)terminals at the current * position. * For each element of t and nt, an outgoing edge and a (temporary) destination * state is created. * For all items [x -> a . y b, L], add [x -> a y . b, L] to the set of * initial items of the appropriate destination state. * @returns destination states for the transitions outgoing from this state. */ calcItemSet(): LR1_State[]; /** * Calculate REDUCE entries for the parsing table. * For each item of the state, check if the current position is right to * the last item of the right-hand side. In this case, a reduce entry is * constructed for each item of the lookahead set of that item. * @returns dictionary of table entries for each item of the lookahead set */ calcReduceEntries(): { [terminalId: string]: LR1_TableEntry; }; /** * Stringifies the state. * @returns stringified version of the state */ toString(): string; } /** * State item := item of CLOSURE_1. */ export declare class LR1_StateItem { /** * current position (referred to the items of the right-hand side) */ pos: number; /** * lookahead set := items after the right-most item of the rule. */ lookAheadSet: Set; /** * reference to the rule */ rule: LR1_Rule; /** * Checks if the given item is equal to the current item object. * @param i item that is compared to the current item object * @returns true, if the given item is equal to the present item object; * otherwise false */ equal(i: LR1_StateItem): boolean; /** * Clones the current item object * @returns clone of the current object */ clone(): LR1_StateItem; /** * Compares a given lookahead set to the lookahead set of the current object. * @param l lookahead set to compare to * @returns true, if both sets are equal; otherwise false */ compareLookAhead(l: Set): boolean; /** * Stringifies the state. * @returns stringified version of the state */ toString(): string; } /** * Directed edge (transition) between two states. */ export declare class LR1_Edge { /** * source state */ src: LR1_State; /** * destination state */ dest: LR1_State; /** * label of the transition (type and value of terminal or non-terminal) */ label: LR1_RuleItem; constructor(src: LR1_State, dest: LR1_State); }