Exemplo n.º 1
0
        /// <summary>
        /// Exports the given LR automaton to a DOT graph in the specified file
        /// </summary>
        /// <param name="graph">The LR automaton to export</param>
        /// <param name="file">DOT file to export to</param>
        public static void ExportDOT(Graph graph, string file)
        {
            DOTSerializer serializer = new DOTSerializer("LR", file);

            foreach (Hime.SDK.Grammars.LR.State state in graph.States)
            {
                List <string> items = new List <string>();
                foreach (Item item in state.Items)
                {
                    if (item.Action == Hime.Redist.Parsers.LRActionCode.Reduce)
                    {
                        items.Add(item.ToString());
                    }
                }
                serializer.WriteStructure("state" + state.ID, state.ID.ToString(), items.ToArray());
            }
            foreach (Hime.SDK.Grammars.LR.State state in graph.States)
            {
                foreach (Hime.SDK.Grammars.Symbol symbol in state.Transitions)
                {
                    serializer.WriteEdge("state" + state.ID, "state" + state.GetChildBy(symbol).ID, symbol.ToString());
                }
            }
            serializer.Close();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Exports the given LR automaton to a DOT graph in the specified file
        /// </summary>
        /// <param name="automaton">The LR automaton to export</param>
        /// <param name="file">DOT file to export to</param>
        public static void ExportDOT(LRAutomaton automaton, string file)
        {
            DOTSerializer serializer = new DOTSerializer("LR", file);

            foreach (LRState state in automaton.States)
            {
                string[] items = new string[state.Reductions.Count];
                for (int i = 0; i != state.Reductions.Count; i++)
                {
                    items[i] = state.Reductions[i].ToString();
                }
                string label = state.IsAccept ? state.ID + "=Accept" : state.ID.ToString();
                serializer.WriteStructure("state" + state.ID, label, items);
            }
            foreach (LRState state in automaton.States)
            {
                foreach (LRTransition transition in state.Transitions)
                {
                    serializer.WriteEdge("state" + state.ID, "state" + transition.Target.ID, transition.Label.ToString());
                }
            }
            serializer.Close();
        }