Beispiel #1
0
        public bool TryParse(Tokens tokens, IScope scope, out IStatement statement)
        {
            // This is a block call
            Variable variable = new Variable ( _executorFactory.GetVariableExecutor() );
            variable.Scope = scope;
            variable.Ident = tokens.PullToken ();

            // Check if there is an indexer into the variable
            if (tokens.PeekToken () == "[")
            {
                tokens.PullToken ();
                variable.Indexer = _expressionParser.ParseExpression ( scope, tokens );
                tokens.RemoveNextToken ("]");
            }

            if ( tokens.NextTokenIs("(") )
            {
                // Parse the parameters..
                variable.Parameters = _expressionParser.ParseArray( scope, tokens ) as ArrayExpr;
            }

            statement = variable;
            return true;
        }
Beispiel #2
0
        /// <summary>
        /// Value is a constant string, number or variable name.
        /// </summary>
        /// <param name="tokens"></param>
        /// <returns></returns>
        public Expression ParseValue( IScope scope, Tokens tokens )
        {
            Expression value = null;

            if ( tokens.NextTokenIs ( BeginBlock ) )
            {
                value = _blockParser.GetBlock ( scope, tokens );
            }
            else if ( tokens.PeekToken().StartsWith ( "'" ) && tokens.PeekToken().EndsWith ( "'" ) )
            {
                string literal = tokens.PullToken().Trim ( '\'' );
                value = new StringLiteral
                {
                    Value = literal
                };
            }
            else if ( tokens.PeekToken().IsNumber () )
            {
                value = new NumberLiteral
                {
                    Value = double.Parse ( tokens.PullToken() )
                };
            }
            else if ( tokens.NextTokenIs(BeginArray) )
            {
                return this.ParseArray ( scope, tokens );
            }
            else
            {
                var variable = new Variable ( _executorFactory.GetVariableExecutor () );
                variable.Scope = scope;
                variable.Ident = tokens.PullToken();

                // Check if there is an indexer into the variable
                if (tokens.PeekToken () == "[")
                {
                    tokens.PullToken ();
                    variable.Indexer = ParseExpression ( scope, tokens );
                    tokens.RemoveNextToken ("]");
                }

                value = variable;
            }

            return value;
        }