private void GenerateNewParserStatesThruShifts(int startIndex, string statePrefix) { // Iterate through states (while new ones are created) and create shift transitions and new states for (int index = startIndex; index < Data.States.Count; index++) { var state = Data.States[index]; //Get all possible shifts foreach (var term in state.BuilderData.ShiftTerms) { var shiftItems = state.BuilderData.ShiftItems.SelectByCurrent(term); //the following constructor assigns Transition prop of items, and adds to state.ShiftTransitions var trans = new ShiftTransition(state, term, shiftItems); //Get set of shifted cores and find/create target state var shiftedCoreItems = shiftItems.GetShiftedCores(); trans.ToState = FindOrCreateState(shiftedCoreItems, statePrefix); //Create shift action var newAction = ParserAction.CreateShift(trans.ToState); state.Actions[term] = newAction; //Link items in old/new states foreach (var shiftItem in shiftItems) { shiftItem.ShiftedItem = trans.ToState.BuilderData.AllItems.FindByCore(shiftItem.Core.ShiftedItem); } //foreach shiftItem } //foreach term //Setup transitions includes and item lookbacks; we have to do it after the "term loop", when all transitions have been // already created and are properly added to state items' lookbacks } //for index //Now for all newly created states and their transitions, compute transition lookahead sources // and setup lookbacks and transition includes ComputeTransitionsLookaheadSources(startIndex); ComputeItemLookbacksAndTransitionIncludes(startIndex); }//method
}//constructor public bool Include(ShiftTransition other) { bool result = Includes.Add(other); if (!result) { return(false); } other.IncludedBy.Add(this); return(result); }