public override IDerivation Expand(DerivationContext aContext) { ListDerivation lList = new ListDerivation(true, aContext); TextDerivation lText = new TextDerivation(Name); //Symbol.Create(mGrammar, Name, true); lList.Add(lText); //add this point to special list for futher replacement PlaceHolders.Add(Name, lText); return(lList); }
private IDerivation GenerateIterativeTopDown() { ListDerivation lRootList = new ListDerivation(true, mGrammar.MainSymbol.Context); lRootList.Add(ExpandNonTerminal(mGrammar.MainSymbol)); ListDerivation lListDer = null; ListDerivation lNextListDer = lRootList; MaxListDerLevel = 0; ListDerivation fixedLevel = null; while (null != lNextListDer) { lListDer = lNextListDer; lNextListDer = lListDer.ExpandStep(); // fire progress event if (Progress != null && lNextListDer != null) { if (lNextListDer.Level == 2) { fixedLevel = lNextListDer; //MessageBox.Show(fixedLevel.ToString()); } if (lNextListDer.Level > MaxListDerLevel) { MaxListDerLevel = lNextListDer.Level; } //GenerateProgressEventArgs e = new GenerateProgressEventArgs // { // RootText = lRootList.ToString(), // CurrentListText = lNextListDer.ToString(), // CurrentListLevel = lNextListDer.Level, // MaxLevel = MaxListDerLevel, // CurrentInCurrent = lNextListDer.mCurrentItemIndex // }; //if (fixedLevel != null) //{ // e.CurrentInRoot = fixedLevel.mCurrentItemIndex; // e.TotalInRoot = fixedLevel.mList.Count; //} //if (PauseGenerate) //{ // e.PausedAtList = lNextListDer; //} //Progress(this, e); while (PauseGenerate) { Thread.Sleep(100); } } } return(lListDer); }
private IDerivation ExpandInternal(int aMin, int aMax, DerivationContext aContext) { ListDerivation lList = new ListDerivation(true, aContext); int rest = 0; if (aMax != int.MaxValue) { rest = mRnd.Next(aMax - aMin + 1); } for (int i = 0; i < aMin + rest; i++) { lList.Add(Phrase.Expand(aContext)); } //есил 5..* генерим, пока не выпадет орел :) if (aMax == int.MaxValue) { while (mRnd.Next(2) >= 1) { lList.Add(Phrase.Expand(aContext)); } } return(lList); }
private ListDerivation GenerateIterativeLeftRight(DerivationContext aLContext) { ListDerivation lCurDerivationList = new ListDerivation(true, aLContext); //начало - генерируем первый вывод в цепочке вывода lCurDerivationList.Add(mGrammar.MainSymbol.Accept(aLContext)); bool lDeriving = true; while (lDeriving) { lDeriving = false; //log //TLog.Write("===>" + lCurDerivationList); // fire progress event if (Progress != null && lCurDerivationList != null) { GenerateProgressEventArgs e = new GenerateProgressEventArgs { RootText = lCurDerivationList.ToString(), }; Progress(this, e); } //создаем новый список и переписываем в него lCurDerivationList раскрывая нетерминалы ListDerivation lNewDerivationList = new ListDerivation(true, aLContext); //Просматриваем список на предмет нетерминалов и раскрываем их for (int i = 0; i < lCurDerivationList.mList.Count; i++) { SymbolDerivation lNonTermSym = lCurDerivationList[i] as SymbolDerivation; if (null != lNonTermSym) { //раскрываем нетерминал lDeriving = true; IDerivation lDer = ExpandNonTerminal(lNonTermSym.Symbol); //вставить результат в новый список if (lDer is ListDerivation) { ListDerivation list = (ListDerivation)lDer; foreach (IDerivation ddd in list.mList) { lNewDerivationList.Add(ddd); } } else { lNewDerivationList.Add(lDer); } } else { //скопировать терминал в новый список lNewDerivationList.Add(lCurDerivationList[i]); } //SpecGraphBuilder.RootObject = lNewDerivationList; //Thread.Sleep(500); } lCurDerivationList = lNewDerivationList; } if (Grammar.SpecGraphBuilder != null) { Grammar.SpecGraphBuilder.RootObject = lCurDerivationList; } return(lCurDerivationList); }
public IDerivation AddEnd(IDerivation aValue) { TargetList.Add(aValue); return(aValue); }