Exemple #1
0
        public Node Parse()
        {
            Node root = null;

            // Initialize parser
            if (!_initialized)
            {
                Prepare();
            }

            this._tokens.Clear();
            this._errorLog      = new ParserLogException();
            this._errorRecovery = -1;

            // Parse input
            try {
                root = ParseStart();
            } catch (ParseException e) {
                AddError(e, true);
            }

            // Check for errors
            if (_errorLog.Count > 0)
            {
                throw _errorLog;
            }

            return(root);
        }
Exemple #2
0
        private Node Analyze(Node node, ParserLogException log)
        {
            var errorCount = log.Count;

            if (node is Production)
            {
                var prod = (Production)node;
                prod = NewProduction(prod.Pattern);
                try {
                    Enter(prod);
                } catch (ParseException e) {
                    log.AddError(e);
                }

                for (int i = 0; i < node.Count; 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 #3
0
        public Node Analyze(Node node)
        {
            ParserLogException log = new ParserLogException();

            node = Analyze(node, log);
            if (log.Count > 0)
            {
                throw log;
            }

            return(node);
        }