public bool Include(ShiftTransitionSet includeTransitions) { bool result = false; foreach (var trans in includeTransitions) { result |= Include(trans); } return(result); }
//VERY inefficient - should be reimplemented using SCC (strongly-connected components) algorithm for efficient computation // of transitive closures private void PropagateTransitionsIncludes(int startStateIndex) { int time = 0; //initial recompute set includes all transitons over non-terminals var recomputeSet = new ShiftTransitionSet(); for (int i = startStateIndex; i < Data.States.Count; i++) { var state = Data.States[i]; foreach (var trans in state.BuilderData.ShiftTransitions) { if ((trans.OverTerm is NonTerminal)) { trans._lastChanged = 0; //reset time fields trans._lastChecked = 0; recomputeSet.Add(trans); } } } var newIncludes = new ShiftTransitionSet(); //temp set while (recomputeSet.Count > 0) { var newRecomputeSet = new ShiftTransitionSet(); foreach (var trans in recomputeSet) { newIncludes.Clear(); foreach (var child in trans.Includes) { if (child._lastChanged >= trans._lastChecked) { newIncludes.UnionWith(child.Includes); } } trans._lastChecked = time++; var oldCount = trans.Includes.Count; trans.Includes.UnionWith(newIncludes); if (trans.Includes.Count > oldCount) { trans._lastChanged = time; newRecomputeSet.UnionWith(trans.IncludedBy); } } //foreach trans recomputeSet = newRecomputeSet; } //while recomputeSet.Count > 0 }
//VERY inefficient - should be reimplemented using SCC (strongly-connected components) algorithm for efficient computation // of transitive closures private void PropagateTransitionsIncludes(int startStateIndex) { int time = 0; //initial recompute set includes all transitons over non-terminals var recomputeSet = new ShiftTransitionSet(); for (int i = startStateIndex; i < Data.States.Count; i++) { var state = Data.States[i]; foreach (var trans in state.BuilderData.ShiftTransitions) if ((trans.OverTerm is NonTerminal)) { trans._lastChanged = 0; //reset time fields trans._lastChecked = 0; recomputeSet.Add(trans); } } var newIncludes = new ShiftTransitionSet(); //temp set while (recomputeSet.Count > 0) { var newRecomputeSet = new ShiftTransitionSet(); foreach (var trans in recomputeSet) { newIncludes.Clear(); foreach (var child in trans.Includes) if (child._lastChanged >= trans._lastChecked) newIncludes.UnionWith(child.Includes); trans._lastChecked = time++; var oldCount = trans.Includes.Count; trans.Includes.UnionWith(newIncludes); if (trans.Includes.Count > oldCount) { trans._lastChanged = time; newRecomputeSet.UnionWith(trans.IncludedBy); } }//foreach trans recomputeSet = newRecomputeSet; }//while recomputeSet.Count > 0 }