public void WriteGv(IGraphView graph) { graph.BeginDigraph("LRFSM"); //graph.SetGraphProperties(RankDir.LeftToRight); int stateCount = automata.States.Count; foreach (var state in automata.States) { graph.AddNode(state.Index, shape: Shape.Mrecord, label: StateToHtml(state.Index)); } foreach (var state in automata.States) { foreach (var transition in state.Transitions) { foreach (var action in transition.Actions) { if (action.Kind == ParserActionKind.Shift) { graph.AddEdge(state.Index, action.State, grammar.Symbols[transition.Token].Name); } } } } graph.EndDigraph(); }
void ISppfNodeVisitor.VisitBranch(int ruleIndex, SppfNode[] children, Loc location) { var rule = grammar.Productions[ruleIndex]; var tokenName = grammar.Symbols[rule.OutcomeToken].Name; string label; if (showRules) { label = string.Format( "{0} -> {1}" #if DEBUG + " t: " + currentNode.timestamp #endif , tokenName, string.Join(" ", from s in rule.Pattern select s.Name)); } else { label = tokenName #if DEBUG + " t: " + currentNode.timestamp #endif ; } graph.AddNode(currentNodeIdentity, label: label, shape: Shape.Ellipse); if (children != null && children.Length != 0) { int i = 0; foreach (var child in children) { graph.AddEdge(currentNodeIdentity, child, label: "child" + ++i); EnqueueNode(child); } } }
public void DescribeGraph(IGraphView view) { var data = this; view.BeginDigraph("tdfa"); view.SetGraphProperties(rankDir: RankDir.LeftToRight); foreach (var S in data.EnumerateStates()) { GraphColor color = S.IsNewline ? GraphColor.Green : GraphColor.Default; if (S.IsAccepting) { view.AddNode(S.Index, GetStateName(S), style: Style.Bold, color: color); } else { view.AddNode(S.Index, GetStateName(S), color: color); } } foreach (var S in data.EnumerateStates()) { foreach (var t in S.Outgoing) { var charSet = data.Alphabet.Decode(t.Symbols); view.AddEdge(t.From, t.To, charSet.ToCharSetString()); } if (S.Tunnel >= 0) { view.AddEdge(S.Index, S.Tunnel, style: Style.Dotted); } } view.EndDigraph(); }
public void WriteGraph(IGraphView view, RuntimeGrammar grammar, int[] stateToSymbol) { var allAccessibleByLayer = GetAllNodes().GroupBy(state => state.Layer); var layers = Enumerable .Range(0, currentLayer + 1) .Select(i => new List <GssNode <T> >(2)) .ToList(); foreach (var group in allAccessibleByLayer) { layers[group.Key].AddRange(group); } view.BeginDigraph("Gss"); view.SetGraphProperties(rankDir: RankDir.RightToLeft); for (int layerIndex = 0; layerIndex != layers.Count; ++layerIndex) { var layer = layers[layerIndex]; view.BeginCluster(layerIndex.ToString()); view.SetGraphProperties(style: Style.Dotted, label: "U" + layerIndex); view.SetNodeProperties(shape: Shape.Circle); for (int nodeIndex = 0; nodeIndex != layer.Count; ++nodeIndex) { view.AddNode( Tuple.Create("s", layerIndex, nodeIndex), label: StateName(layer[nodeIndex])); } view.EndCluster(); } view.SetNodeProperties(shape: Shape.Rect); int linkIndex = 0; for (int layerIndex = 0; layerIndex != layers.Count; ++layerIndex) { var layer = layers[layerIndex]; for (int nodeIndex = 0; nodeIndex != layer.Count; ++nodeIndex) { var from = layer[nodeIndex]; if (from.State < 0) { continue; } int token = stateToSymbol[from.State]; var link = from.FirstLink; while (link != null) { var to = link.LeftNode; view.AddNode(Tuple.Create("t", linkIndex), grammar.SymbolName(token)); view.AddEdge( Tuple.Create("s", layerIndex, nodeIndex), Tuple.Create("t", linkIndex) ); view.AddEdge( Tuple.Create("t", linkIndex), Tuple.Create("s", to.Layer, layers[to.Layer].IndexOf(to)) ); ++linkIndex; link = link.NextLink; } } } view.EndDigraph(); }