public void PrintCommonTree(CommonTree ast, string indent)
 {
     Console.WriteLine(indent + ast.ToString());// + "::" + ast.Token.GetHashCode().ToString());
     //Console.WriteLine(ast.GetType().Name);
     if (ast.Children != null)
     {
         indent += "  ";
         foreach (var child in ast.Children)
         {
             var childTree = child as CommonTree;
             //if (childTree.Text != EOF)
             {
                 PrintCommonTree(childTree, indent);
             }
         }
     }
 }
        public void writeXMLNode(CommonTree ast, XmlWriter writer)
        {
            writer.WriteStartElement(ast.ToString());
            //writer.WriteAttributeString("line", ast.Token.TokenIndex.ToString());

            IList<CommonTree> children = ast.Children as IList<CommonTree>;
            if (ast.Children != null)
            {
                CommonTree firstChild = (CommonTree)ast.Children[0];
                if (ast.Children[0] is CommonErrorNode)
                {
                    createXMLErrorNode((CommonErrorNode)ast.Children[0], writer);
                }
                else if (firstChild.Token.TokenIndex > 0)
                {
                    writer.WriteAttributeString("value", firstChild.Token.Text);
                }
                else
                {
                    writeXMLNode(firstChild as CommonTree, writer);
                }

                for (int i = 1; i < ast.ChildCount; i++)
                {
                    if (ast.Children[i] is CommonErrorNode)
                    {
                        createXMLErrorNode((CommonErrorNode)ast.Children[i], writer);
                    }
                    else
                    {
                        writeXMLNode(ast.Children[i] as CommonTree, writer);
                    }
                }

            }
            writer.WriteEndElement();
        }
예제 #3
0
 private static void DumpTree(CommonTree r, int ind)
 {
     Console.Write(new string('\t', ind));
     Console.WriteLine(r.ToString());
     if (r.Children != null)
     {
         foreach (CommonTree t in r.Children)
         {
             DumpTree(t, ind + 1);
         }
     }
 }