Parse() public method

Runs the parser over the inserted query.
public Parse ( ) : ParseEngine
return ParseEngine
示例#1
0
        /// <summary>
        /// Begins the interpretation of the current parse tree.
        /// </summary>
        /// <param name="values">A dictionary with additional symbols to consider.</param>
        internal void Interpret(Dictionary <string, Value> values)
        {
            if (!parser.CanRun)
            {
                if (!parser.IsParsed)
                {
                    parser.Parse();
                }

                if (parser.HasErrors)
                {
                    throw new YAMPParseException(parser);
                }
            }

            currentStatement = null;
            _stop            = false;

            foreach (var statement in parser.Statements)
            {
                if (_stop)
                {
                    break;
                }

                currentStatement = statement;
                Output           = statement.Interpret(values);
            }

            if (currentStatement != null && Output != null)
            {
                if (!currentStatement.IsAssignment)
                {
                    if (Output is ArgumentsValue)
                    {
                        Output = ((ArgumentsValue)Output).First();
                    }

                    Context.AssignVariable(YAMP.Parser.answer, Output);
                }
            }
        }
        /// <summary>
        /// Begins the interpretation of the current parse tree.
        /// </summary>
        /// <param name="values">A dictionary with additional symbols to consider.</param>
        public void Run(Dictionary <String, Value> values)
        {
            if (!_parser.CanRun)
            {
                if (!_parser.IsParsed)
                {
                    _parser.Parse();
                }

                if (_parser.HasErrors)
                {
                    throw new YAMPParseException(_parser);
                }
            }

            _current = null;
            _stop    = false;

            foreach (var statement in _parser.Statements)
            {
                if (_stop)
                {
                    break;
                }

                _current = statement;
                Output   = statement.Interpret(values);
            }

            if (_current != null && Output != null)
            {
                if (!_current.IsAssignment)
                {
                    if (Output is ArgumentsValue)
                    {
                        Output = ((ArgumentsValue)Output).First();
                    }

                    Context.AssignVariable(_context.Answer, Output);
                }
            }
        }