Exemplo n.º 1
0
        private bool ParseOperator(Tokenizer tokenizer, TokenOperator token)
        {
            // Handle ternary
            if (token.OpType == TokenOperator.OperatorType.TernaryTrue)
            {
                tokenizer.Next();
                return(ParseTernaryOperator(tokenizer, token));
            }
            else if (token.OpType == TokenOperator.OperatorType.VectorStart)
            {
                tokenizer.Next();
                return(ParseVector(tokenizer, true));
            }

            Operations.Function func = Operations.LookupOperator(token.OpType, 2);

            if (func == null)
            {
                return(Error("Unknown operator `" + token.Text + "'", tokenizer));
            }

            tokenizer.Next();

            if (!ParseExpression(tokenizer, token.Properties.Priority, token.Properties.LeftAssoc))
            {
                return(false);
            }

            d_instructions.Add(new InstructionFunction(token.Text, func, 2));
            return(true);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
 public InstructionFunction(string name, Operations.Function function, int numargs)
 {
     Name     = name;
     Function = function;
     NumArgs  = numargs;
 }