コード例 #1
0
ファイル: Arbol.cs プロジェクト: JaredOsuna/Proyecto1Compi2
        public static string graficarNodo(NodoSintactico nodo)
        {
            string cadena = "";

            foreach (NodoSintactico hijos in nodo.getHijos())
            {
                String nodoPadre = "";
                String nodoHijo  = "";
                if (nodo.getValor() != null)
                {
                    nodoPadre = "\"" + nodo.getNumNodo() + "_" + nodo.getNombre() + "\"" + "[label = \"" + nodo.getValor() + "\"];";
                }
                else
                {
                    nodoPadre = "\"" + nodo.getNumNodo() + "_" + nodo.getNombre() + "\"" + "[label = \"" + nodo.getNombre() + "\"];";
                }
                if (hijos.getValor() != null)
                {
                    nodoHijo = "\"" + hijos.getNumNodo() + "_" + hijos.getNombre() + "\"" + "[label = \"" + hijos.getValor() + "\"];";
                }
                else
                {
                    nodoHijo = "\"" + hijos.getNumNodo() + "_" + hijos.getNombre() + "\"" + "[label = \"" + hijos.getNombre() + "\"];";
                }
                String apuntadorPadre = "\"" + nodo.getNumNodo() + "_" + nodo.getNombre() + "\"";
                String apuntadorHijo  = "\"" + hijos.getNumNodo() + "_" + hijos.getNombre() + "\"";
                cadena += nodoPadre + "\n" + nodoHijo + "\n" + apuntadorPadre + "->" + apuntadorHijo + ";\n";
                cadena += graficarNodo(hijos);
            }
            return(cadena);
        }
コード例 #2
0
ファイル: Arbol.cs プロジェクト: JaredOsuna/Proyecto1Compi2
 public static String getDot(ParseTreeNode raiz, int tipo, NodoSintactico root)
 {
     grafo    = "digraph G{\n";
     grafo   += "node[shape=\"box\"];\n";
     contador = 1;
     if (tipo == 0)
     {
         grafo += "nodo0[label=\"" + escapar(raiz.ToString()) + "\"];\n";
         recorrerAST("nodo0", raiz);
     }
     else if (tipo == 1)
     {
         grafo += graficarNodo(root);
     }
     grafo += "\n}";
     return(grafo);
 }
コード例 #3
0
        public static void crearImagen(ParseTreeNode raiz, NodoSintactico root, int tipo)
        {
            String grafoDot = Arbol.getDot(raiz, tipo, root);

            try
            {
                // Create the file.
                if (tipo == 0)
                {
                    using (FileStream fs = File.Create(@"C:\compiladores2\ArbolIrony.dot"))
                    {
                        Byte[] info = new UTF8Encoding(true).GetBytes(grafoDot);
                        fs.Write(info, 0, info.Length);
                    }
                }
                else if (tipo == 1)
                {
                    using (FileStream fs = File.Create(@"C:\compiladores2\ArbolModificado.dot"))
                    {
                        Byte[] info = new UTF8Encoding(true).GetBytes(grafoDot);
                        fs.Write(info, 0, info.Length);
                    }
                }
                Process          process   = new Process();
                ProcessStartInfo startInfo = new ProcessStartInfo();
                startInfo.WindowStyle = ProcessWindowStyle.Hidden;
                startInfo.FileName    = "cmd.exe";
                if (tipo == 0)
                {
                    startInfo.Arguments = "/C dot -Tpng C:/compiladores2/ArbolIrony.dot -o C:/compiladores2/ArbolIrony.png";
                }
                else
                {
                    startInfo.Arguments = "/C dot -Tpng C:/compiladores2/ArbolModificado.dot -o C:/compiladores2/ArbolModificado.png";
                }
                process.StartInfo = startInfo;
                process.Start();
            }

            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }