private SituationSegment BuildSituationSegment(IShiftPredicate Predicate, ISituationSegment NextSegment) { Situation situation; ShiftTransition transition; SituationSegment result; situation = new Situation(); situation.Transitions.AddRange(NextSegment.InputTransitions); transition = new ShiftTransition(); transition.Predicate = Predicate; transition.TargetSituation = situation; result = new SituationSegment(); result.InputTransitions.Add(transition); result.OutputSituations.Add(situation); return(result); }
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); }