Esempio n. 1
0
        void ISppfNodeVisitor.VisitLeaf(int token, object value, Loc location)
        {
            string label = grammar.Symbols[token].Name + " pos: " + location.Position
#if DEBUG
                           + " t: " + currentNode.timestamp
#endif
            ;

            graph.AddNode(currentNodeIdentity, label: label, shape: Shape.Circle);
        }
Esempio n. 2
0
        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();
        }
Esempio n. 3
0
        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();
        }
Esempio n. 4
0
        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();
        }
Esempio n. 5
0
        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();
        }