private static void concatenar(ParseTreeNode nodoIrony) { if (nodoIrony.ChildNodes.Count == 0) { if (nodoIrony.Token == null) { //no terminal sin hijos /// Console.WriteLine("NoTerminal->" + nodoIrony.ToString()); grafo += nodoIrony.GetHashCode() + "[label=\"" + nodoIrony.ToString() + "\"];\n"; } else { String terminal = escapar(nodoIrony.Token.Value.ToString()); String nombreTerminal = nodoIrony.Term.Name; //Console.WriteLine("terminal->"+terminal); grafo += nodoIrony.GetHashCode() + "[label=\"(" + nombreTerminal + ") " + terminal + "\"];\n"; } } else { // Console.WriteLine("NoTerminal2->" + nodoIrony.ToString()); grafo += nodoIrony.GetHashCode() + "[label=\"" + nodoIrony + "\"];\n"; } foreach (ParseTreeNode hijo in nodoIrony.ChildNodes) { grafo += nodoIrony.GetHashCode() + "->" + hijo.GetHashCode() + ";\n"; concatenar(hijo); } }
public static void Generar(ParseTreeNode raiz) { graph = graph + "nodo" + raiz.GetHashCode() + "[label=\"" + raiz.ToString().Replace("\"", "\\\"") + " \", fillcolor=\"LightBlue\" , style =\"filled\" , shape=\"box\"]; \n"; if (raiz.ChildNodes.Count > 0) { ParseTreeNode[] hijos = raiz.ChildNodes.ToArray(); for (int i = 0; i < raiz.ChildNodes.Count; i++) { Generar(hijos[i]); graph = graph + "\"nodo" + raiz.GetHashCode() + "\"-> \"nodo" + hijos[i].GetHashCode() + "\" \n"; } } }
private static void Generar(ParseTreeNode raiz) { graph = graph + "nodo" + raiz.GetHashCode() + "[label=\"" + raiz.ToString() + " \"]; \n"; if (raiz.ChildNodes.Count > 0) { ParseTreeNode[] hijos = raiz.ChildNodes.ToArray(); for (int i = 0; i < raiz.ChildNodes.Count; i++) { Generar(hijos[i]); graph = graph + "\"nodo" + raiz.GetHashCode() + "\"-> \"nodo" + hijos[i].GetHashCode() + "\" \n"; } } }
//-------------------------------------------------- RECORRE TODO EL ARBOL GUARDANDOLO EN UN ARCHIVO-------------------------------------------------------- public static void recorrer(ParseTreeNode raiz, System.IO.StreamWriter f) { if (raiz != null) { f.Write("nodo" + raiz.GetHashCode() + "[label=\"" + raiz.ToString().Replace("\"", "\\\"") + " \", fillcolor=\"LightBlue\", style =\"filled\", shape=\"box\"]; \n"); if (raiz.ChildNodes.Count > 0) { ParseTreeNode[] hijos = raiz.ChildNodes.ToArray(); for (int i = 0; i < raiz.ChildNodes.Count; i++) { recorrer(hijos[i], f); f.Write("\"nodo" + raiz.GetHashCode() + "\"-> \"nodo" + hijos[i].GetHashCode() + "\" \n"); } } } }
public void graficar_arbol(ParseTreeNode pt_root) { if (pt_root != null) { escribir.Write(pt_root.GetHashCode() + "[shape = ellipse ,label=\"" + pt_root.Term.Name.ToString() + "\"];\n"); if (pt_root.ChildNodes.Count > 0) { ParseTreeNode[] hijos = pt_root.ChildNodes.ToArray(); for (int cont = 0; cont < pt_root.ChildNodes.Count; cont++) { graficar_arbol(hijos[cont]); escribir.Write(pt_root.GetHashCode() + "->" + hijos[cont].GetHashCode() + ";\n"); } } } }
public string GraficarNodo(ParseTreeNode raiz) { string nodoString = ""; //MessageBox.Show("label = "+raiz.ToString()); string label = raiz.ToString().Replace("\"", "\\\""); //caracteres especiales nodoString = "nodo" + raiz.GetHashCode() + "[label=\"" + label + " \", fillcolor=\"blanchedalmond\", style =\"filled\", shape=\"box\"]; \n"; if (raiz.ChildNodes.Count > 0) { ParseTreeNode[] hijos = raiz.ChildNodes.ToArray(); for (int i = 0; i < raiz.ChildNodes.Count; i++) { nodoString += GraficarNodo(hijos[i]); nodoString += "\"nodo" + raiz.GetHashCode() + "\"-> \"nodo" + hijos[i].GetHashCode() + "\" \n"; } } return(nodoString); }
/// <summary> /// Metodo recursivo para generar la lista de strings del dot de un nodo /// </summary> /// <param name="node"></param> /// <param name="container"></param> private static void IGetDot(ParseTreeNode node, LinkedList <String> container) { if (node == null) { return; } string term = Convert.ToString(node.Term); string val = Convert.ToString(node.Token); if (val.IndexOf('(') >= 0) { val = val.Substring(0, val.IndexOf('(')); } container.AddLast(node.GetHashCode().ToString() + "[ label = \"" + term + "\\n" + val + "\" ];"); foreach (var child in node.ChildNodes) { IGetDot(child, container); container.AddLast(node.GetHashCode().ToString() + "->" + child.GetHashCode() + ";"); } }
public void Generar(ParseTreeNode raiz) { graph = graph + "nodo" + raiz.GetHashCode() + "[label=\"" + raiz.ToString().Replace("\"", "\\\"") + " \", fillcolor=\"red\", style =\"filled\", shape=\"circle\"]; \n"; if (raiz.ChildNodes.Count > 0) { ParseTreeNode[] hijos = raiz.ChildNodes.ToArray(); for (int i = 0; i < raiz.ChildNodes.Count; i++) { Generar(hijos[i]); graph = graph + "\"nodo" + raiz.GetHashCode() + "\"-> \"nodo" + hijos[i].GetHashCode() + "\" \n"; } } }