public override IDerivation Visit(NonTerminal aSymbol, DerivationContext aContext) { tGraph graph = (aContext as BuildGraphContext).BuildingGraph; if ((aSymbol.CycicKind & CycicKind.CyclicOrigin) > 0) { graph.ensureExistsNode(aSymbol.CounterName, aSymbol.Text); graph.ensureExistsNode(aSymbol.CyclicToOccurence, aSymbol.Text); tEdge e = graph.addEdge(aSymbol.CounterName, aSymbol.CyclicToOccurence); if (e != null) { e.CustomAttributes = GrammarGraphEdgeAttrs.IsPunktir; } } if (aSymbol.CycicKind == CycicKind.None || aSymbol.CycicKind == CycicKind.CyclicPropagated) { aSymbol.FindItsRule().Expand(aContext); } return(null); }
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); }