示例#1
0
        private bool ParseFunction(Tokenizer tokenizer, TokenIdentifier identifier)
        {
            Token next    = tokenizer.Peek();
            bool  loopit  = true;
            int   numargs = 0;

            if (next != null && (next is TokenOperator) && ((TokenOperator)next).OpType == TokenOperator.OperatorType.GroupEnd)
            {
                // Consume group end
                tokenizer.Next();
                loopit = false;
            }

            while (loopit)
            {
                if (!ParseExpression(tokenizer, -1, false))
                {
                    return(false);
                }

                ++numargs;

                // See what is next
                next = tokenizer.Peek();

                if (next == null || !(next is TokenOperator))
                {
                    return(Error("Expected `operator', but got " + (next != null ? next.Text : "(nothing)"), tokenizer));
                }

                TokenOperator nextop = next as TokenOperator;

                if (nextop.OpType == TokenOperator.OperatorType.GroupEnd)
                {
                    // Consume it
                    tokenizer.Next();
                    break;
                }
                else if (nextop.OpType != TokenOperator.OperatorType.Comma)
                {
                    return(Error("Expected `,' but got " + next.Text, tokenizer));
                }

                // Consume token
                tokenizer.Next();
            }

            Operations.Function func = Operations.LookupFunction(identifier.Text, numargs);

            if (func == null)
            {
                return(Error(String.Format("Invalid function `{0}' for provided arguments", identifier.Text), tokenizer));
            }

            d_instructions.Add(new InstructionFunction(identifier.Text, func, numargs));
            return(true);
        }
示例#2
0
        private bool ParseIdentifier(Tokenizer tokenizer, TokenIdentifier identifier)
        {
            bool ret = false;

            // Consume token and peek the next to see if the identifier is a function call
            tokenizer.Next();
            Token         next   = tokenizer.Peek();
            TokenOperator nextop = next != null ? next as TokenOperator : null;

            if (nextop != null && nextop.OpType == TokenOperator.OperatorType.GroupStart)
            {
                // Consume peeked group start
                tokenizer.Next();
                ret = ParseFunction(tokenizer, identifier);
            }
            else
            {
                d_instructions.Add(new InstructionIdentifier(identifier.Text.Split(new char[] { '.' })));
                ret = true;
            }

            return(ret);
        }