public static UIElement CreateControl(IPhrase element, List <string> aOuterSymbols) { if (element is Seqence) { MainWindow.AllSequenses++; return(new SeqenceControl(element as Seqence, aOuterSymbols)); } else if (element is AlternativeSet) { MainWindow.AllAlternativeSets++; return(new AlternativeControl(element as AlternativeSet, aOuterSymbols)); } else if (element is QuantifiedPhrase) { return(new QuantifierControl(element as QuantifiedPhrase, aOuterSymbols)); } else if (element is NonTerminal) { NonTerminal s = element as NonTerminal; MainWindow.AllNonTerminals++; return(new NonTerminalControl(s, aOuterSymbols)); } else if (element is Terminal) { Terminal s = element as Terminal; Label l = new Label(); l.Content = s.Text; //Run r = new Run(s.Text); l.Foreground = Brushes.Red; return(l); } Label unk = new Label(); if (element is AccessSeq) { AccessSeq acc = element as AccessSeq; unk.Content = "#" + acc.ObjectName + "." + acc.mFieldName; } else if (element is TransCallPhrase) { TransCallPhrase trans = element as TransCallPhrase; unk.Content = "call " + trans.BindedMethod.Name; } else if (element is AccessArray) { AccessArray ar = element as AccessArray; unk.Content = ar.ObjectName + "[" + ar.IndexExpr.ToString() + "]"; } else { unk.Content = "unknown:" + element.ToString(); } return(unk); }
public override string ToString() { string result = "<" + Name + ">"; if (Add) { result += "+"; } result += "="; result += RightPhrase.ToString(); return(result); }
public override string ToString() { string phr = Phrase.ToString(); if (Min == 0 && Max == 1) { return(string.Format("[ {0} ]", phr)); } else if (Phrase is NonTerminal || Phrase is Terminal) { return(string.Format("{0}{1}", phr, QuantSign)); } else { return(string.Format("({0}){1}", phr, QuantSign)); } }
public override IDerivation Visit(AlternativeSet aAlternativeSet, DerivationContext aContext) { bool allIsCyclic = true; // allIsCyclic сохранит значение true в том и только том случае, если все логические сомножетели true for (int i = 0; i < aAlternativeSet.Count && allIsCyclic; i++) { //allIsCyclic = allIsCyclic & aAlternativeSet.Phrases[i].IsCyclic; allIsCyclic &= aAlternativeSet.Phrases[i].IsCyclic; } if (allIsCyclic) { IPhrase p = aAlternativeSet.Parent; while (p != null && !(p is NonTerminal)) { p = p.Parent; } string ruleName = (p != null) ? p.ToString() : "main"; Log += string.Format("В правиле {0} набор альтернатив {1} ошибка - все альтернативы циклические.\r\n", ruleName, aAlternativeSet); } return(base.Visit(aAlternativeSet, aContext)); }
public string ParseToString(TokenStream ts) { IPhrase phrase = Parse(ts); return(phrase == null ? "" : phrase.ToString()); }
private tEdge addEdge(DerivationContext aContext, IPhrase aPhr, IPhrase aParent) { tGraph graph = (aContext as BuildGraphContext).BuildingGraph; string fromName = "unk"; string toName = "unk"; // determine fromName if (aParent == null) { fromName = aContext.Grammar.MainSymbol.CounterName; graph.ensureExistsNode(fromName, aContext.Grammar.MainSymbol.Text); } else { NonTerminal parentNt = aParent as NonTerminal; if (parentNt != null) { fromName = parentNt.CounterName; graph.ensureExistsNode(parentNt.CounterName, parentNt.Text); } else { fromName = (aContext as BuildGraphContext).GeneratedToName; Debug.Assert(!string.IsNullOrEmpty(fromName), "Не должно быть"); } } // determine toName NonTerminal nonTerminal = aPhr as NonTerminal; Terminal terminal = aPhr as Terminal; if (nonTerminal != null) { toName = nonTerminal.CounterName; string text = nonTerminal.Text; if ((nonTerminal.CycicKind & CycicKind.SkippedAsSeen) > 0) { text += " *"; } graph.ensureExistsNode(toName, text); } else if (terminal != null) { string text = string.IsNullOrEmpty(terminal.Text) ? "e" : terminal.Text; tNode n = graph.addNonUniqueNode(text); toName = n.Name; n.CustomAttributes = "term"; } else { toName = graph.addNonUniqueNode(aPhr.ToString()).Name; //надо запомнить это в контексте (aContext as BuildGraphContext).GeneratedToName = toName; } tEdge e = graph.addEdge(fromName, toName); if (e == null) { Debug.WriteLine("не создалась дуга, потому что нет вершин"); } return(e); }