示例#1
0
        internal FunctionInvocationExpression GenFunctionInvocationExpression(IScope scope, int maxDepth)
        {
            FunctionInvocationExpression fi = new FunctionInvocationExpression();

            fi.Function = GenFunctionExpression(scope);
            GenVariableInvocationExpression(fi, scope, maxDepth);
            return(fi);
        }
示例#2
0
        internal FunctionInvocationExpression GenFunctionInvocationExpression(IScope scope, int maxDepth)
        {
            FunctionInvocationExpression fi = new FunctionInvocationExpression();

            fi.Function = GenFunctionExpression(scope);
            int paramCount = _options.FunctionParametersCountRange.RandomValue(_rand);

            while (paramCount-- > 0)
            {
                fi.Parameters.Add(GenExpression(scope, maxDepth));
            }
            return(fi);
        }
示例#3
0
        // An expression starts out with a starting value, which we get from GetNextValue
        // Functions are applied to that starting value
        // Each function has a "tier", which means how many tokens can go after it
        // toks: the max amount of tokens that should be parsed (determined by tier)
        private Expression ParseExpression(bool topLevel = false, int toks = -1)
        {
            var val = GetNextValue(ref toks);

            while (!tokenizer.EOF() && toks != 0 && tokenizer.Peek().Type == TokenType.Function)
            {
                // Another token has been consumed; therefore we need to update the breaks
                var next = tokenizer.Next().Value;
                toks--;

                if (Function.IsUnary(next))
                {
                    val = new FunctionInvocationExpression(val, next);
                }
                else
                {
                    var tier = Function.GetTier(next);
                    var arg  = ParseExpression(false, tier);
                    val = new FunctionInvocationExpression(val, next, arg);
                }
                // Get rid of all the brackets if this expression is a top level one
                // And also clear out all the breaks
                if (topLevel)
                {
                    bracket = -1;
                    while (IsBracket())
                    {
                        tokenizer.Next();
                    }
                }
                else
                {
                    ProcessBrackets();
                }
            }
            //If a '?' follows this expression, it means it's a conditional expression
            if (!tokenizer.EOF() && tokenizer.Peek().Type == TokenType.Punctuation && tokenizer.Peek().Value == IF.ToString())
            {
                tokenizer.Next();
                val = new ConditionalExpression(val, ParseExpression(), ParseExpression());
            }
            return(val);
        }