Example #1
0
        private AST.Node BuildDyadic(AST.Token symbol, AST.Node lhs, AST.Node rhs)
        {
            AST.Node node;

            if (lhs is AST.BuiltInFunction)
            {
                /* This will allow the following construct:
                 *  ((-)) * 5
                 */
                node = BuildMonadic(((AST.BuiltInFunction)lhs).Function, BuildMonadic(symbol, rhs));
            }
            else if (lhs is AST.BuiltInOperator)
            {
                /* This will allow the following construct:
                 *  ((-each)) * 5
                 */

                AST.Operator op = ((AST.BuiltInOperator)lhs).Operator;
                op.RightArgument = BuildMonadic(symbol, rhs);

                node = op;
            }
            else
            {
                switch (symbol.Type)
                {
                case Tokens.DO:
                    node = AST.Node.DyadicDo(lhs, rhs);
                    break;

                case Tokens.RESULT:     // Tokens.Assign
                    AssignmentPreprocessor(lhs);
                    node = AST.Node.Assign(lhs, rhs);
                    break;

                default:
                    if (rhs is AST.ExpressionList)
                    {
                        throw new ParseException("Incorrect call format", false);
                    }

                    node = AST.Node.DyadicFunction(symbol, lhs, rhs);
                    break;
                }
            }

            return(node);
        }
Example #2
0
        private AST.Node BuildMonadic(AST.Token symbol, AST.Node argument)
        {
            AST.Node node;

            if (symbol.Type == Tokens.DO)
            {
                node = AST.Node.MonadicDo(argument);
            }
            else if (argument is AST.ExpressionList)
            {
                node = AST.Node.BuiltinInvoke(symbol, (AST.ExpressionList)argument);
            }
            else
            {
                node = AST.Node.MonadicFunction(symbol, argument);
            }

            return(node);
        }