Exemple #1
0
        //*
        // * Analyzes a parse tree node by traversing all it's child nodes.
        // * The tree traversal is depth-first, and the appropriate
        // * callback methods will be called. If the node is a production
        // * node, a new production node will be created and children will
        // * be added by recursively processing the children of the
        // * specified production node. This method is used to process a
        // * parse tree after creation.
        // *
        // * @param node the parse tree node to process
        // * @param log the parser error log
        // *
        // * @return the resulting parse tree node
        //

        private Node Analyze(Node node, ParserLogException log)
        {
            Production prod       = default(Production);
            int        errorCount = 0;

            errorCount = log.Count;
            if (node is Production)
            {
                prod = (Production)node;
                prod = new Production(prod.Pattern);
                try
                {
                    Enter(prod);
                }
                catch (ParseException e)
                {
                    log.AddError(e);
                }
                for (int i = 0; i <= node.Count - 1; i++)
                {
                    try
                    {
                        Child(prod, Analyze(node[i], log));
                    }
                    catch (ParseException e)
                    {
                        log.AddError(e);
                    }
                }
                try
                {
                    return(Exit(prod));
                }
                catch (ParseException e)
                {
                    if (errorCount == log.Count)
                    {
                        log.AddError(e);
                    }
                }
            }
            else
            {
                node.Values.Clear();
                try
                {
                    Enter(node);
                }
                catch (ParseException e)
                {
                    log.AddError(e);
                }
                try
                {
                    return(Exit(node));
                }
                catch (ParseException e)
                {
                    if (errorCount == log.Count)
                    {
                        log.AddError(e);
                    }
                }
            }
            return(null);
        }
Exemple #2
0
        //*
        // * Called when adding a child to a parse tree node. By default
        // * this method adds the child to the production node. A subclass
        // * can override this method to handle each node separately. Note
        // * that the child node may be null if the corresponding exit()
        // * method returned null.
        // *
        // * @param node the parent node
        // * @param child the child node, or null
        // *
        // * @throws ParseException if the node analysis discovered errors
        //

        public virtual void Child(Production node, Node child)
        {
            node.AddChild(child);
        }