示例#1
0
        /// <summary>
        /// creates an XML Tree from this AST to view it with XML Viewer eg XMLSpy
        /// </summary>
        /// <param name="astRoot">ASTTree Root</param>
        /// <returns>XML Tree</returns>
        public static string Tree2XML(ASTElement astRoot, int Depth)
        {
            string XmlTree = "";

            if (astRoot != null)
            {
                for (int i = 0; i < Depth; i++)
                {
                    XmlTree += "\t";
                }
                XmlTree += "<Node ";
                XmlTree += "Token=\"" + astRoot.rlElement.GetToken() + "\" ";
                XmlTree += "Terminal=\"" + (astRoot.rlElement.IsTerminal()?"true":"false") + "\" ";
                XmlTree += "Depth=\"" + Depth + "\"";
                XmlTree += ">\n";

                ASTElement tmpAst = null;
                int        NodeNr = 0;
                do
                {
                    tmpAst   = astRoot.GetNextNode(NodeNr);
                    XmlTree += Tree2XML(tmpAst, Depth + 1);
                    NodeNr++;
                }while(tmpAst != null);



                for (int i = 0; i < Depth; i++)
                {
                    XmlTree += "\t";
                }
                XmlTree += "</Node>\n";
            }
            return(XmlTree);
        }
示例#2
0
        private void TraverseTree(ASTElement Node)
        {
            if (Node != null)
            {
                RuleElement re       = Node.rlElement;
                string      Token    = re.GetToken();
                bool        Terminal = re.IsTerminal();
                ExecuteMethod(Token, Terminal);

                ASTElement tmpAst = null;
                int        NodeNr = 0;
                do
                {
                    tmpAst = Node.GetNextNode(NodeNr);
                    TraverseTree(tmpAst);
                    NodeNr++;
                }while(tmpAst != null);
            }
        }