Пример #1
0
        // Usage example of processors and traversers

        static string printTree(Node tree, System.Type traverserType, int method)
        {
            AstPrinter proc = null;

            switch (method)
            {                   // Possible methods to create a processor:
            // use traverser object
            case 1:
                Traverser <bool> vtrav = (Traverser <bool>)Activator.CreateInstance(traverserType);
                proc            = new AstPrinter(vtrav);
                vtrav.Processor = proc;
                break;

            // use 2 steps
            case 2:
                proc = new AstPrinter();
                Activator.CreateInstance(traverserType, proc);
                break;

            // explicitly set traverser
            case 3:
                proc = new AstPrinter();
                Traverser <bool> trav = (Traverser <bool>)Activator.CreateInstance(traverserType, proc);
                trav.Processor = proc;
                proc.traverse  = trav.traverse;
                break;

            default:
                return("");
            }

            proc.Visit(tree);
            return(proc.ToString());
        }
Пример #2
0
 private static void PrintAst(AbstractSyntaxTree ast)
 {
     foreach (GameObjectNode gameObject in ast.Root.GameObjects.Values)
     {
         AstPrinter astPrinter = new AstPrinter();
         astPrinter.Visit(gameObject);
     }
 }