Example #1
0
        public static FunctionExpression Create(
            AphidExpressionContext context_aphidExpressionContext,
            List <AphidExpression> args_list,
            List <AphidExpression> body_list1,
            int value_i,
            int value_i1
            )
        {
            FunctionExpression functionExpression = new FunctionExpression
                                                        (context_aphidExpressionContext, args_list, body_list1);

            ((AphidExpression)functionExpression).Index  = value_i;
            ((AphidExpression)functionExpression).Length = value_i1;
            return(functionExpression);

            // TODO: Edit factory method of FunctionExpression
            // This method should be able to configure the object in all possible ways.
            // Add as many parameters as needed,
            // and assign their values to each field by using the API.
        }
        public static BinaryOperatorBodyExpression Create(
            AphidExpressionContext context_aphidExpressionContext,
            AphidTokenType operator_w,
            FunctionExpression function_functionExpression,
            int value_i,
            int value_i1
            )
        {
            BinaryOperatorBodyExpression binaryOperatorBodyExpression
                = new BinaryOperatorBodyExpression
                      (context_aphidExpressionContext, operator_w, function_functionExpression);

            ((AphidExpression)binaryOperatorBodyExpression).Index  = value_i;
            ((AphidExpression)binaryOperatorBodyExpression).Length = value_i1;
            return(binaryOperatorBodyExpression);

            // TODO: Edit factory method of BinaryOperatorBodyExpression
            // This method should be able to configure the object in all possible ways.
            // Add as many parameters as needed,
            // and assign their values to each field by using the API.
        }
Example #3
0
        private Expression ParseFunctionExpression()
        {
            Expression exp;

            NextToken();

            switch (_currentToken.TokenType)
            {
            case AphidTokenType.LeftParenthesis:
                var funcExp = new FunctionExpression()
                {
                    Args = new List <IdentifierExpression>()
                };

                NextToken();

                if (_currentToken.TokenType != AphidTokenType.RightParenthesis)
                {
                    while (true)
                    {
                        if (_currentToken.TokenType == AphidTokenType.Identifier)
                        {
                            funcExp.Args.Add(ParseIdentifierExpression() as IdentifierExpression);

                            if (_currentToken.TokenType == AphidTokenType.Comma)
                            {
                                NextToken();
                            }
                            else
                            {
                                break;
                            }
                        }
                        else
                        {
                            throw new AphidParserException(_currentToken);
                        }
                    }
                }

                Match(AphidTokenType.RightParenthesis);

                var isSingleLine = _currentToken.TokenType != AphidTokenType.LeftBrace;

                var body = ParseBlock(false);

                if (isSingleLine)
                {
                    funcExp.Body = new List <Expression> {
                        new UnaryOperatorExpression(AphidTokenType.retKeyword, body[0])
                    };
                }
                else
                {
                    funcExp.Body = body;
                }

                exp = funcExp;

                break;

            default:

                exp = new PartialFunctionExpression((CallExpression)ParseCallExpression());
                break;
            }

            return(exp);
        }
Example #4
0
        private Expression ParseFunctionExpression()
        {
            Expression exp;

            NextToken();

            switch (_currentToken.TokenType)
            {
                case AphidTokenType.LeftParenthesis:
                    var funcExp = new FunctionExpression()
                    {
                        Args = new List<IdentifierExpression>()
                    };

                    NextToken();

                    if (_currentToken.TokenType != AphidTokenType.RightParenthesis)
                    {
                        while (true)
                        {
                            if (_currentToken.TokenType == AphidTokenType.Identifier)
                            {
                                funcExp.Args.Add(ParseIdentifierExpression() as IdentifierExpression);

                                if (_currentToken.TokenType == AphidTokenType.Comma)
                                {
                                    NextToken();
                                }
                                else
                                {
                                    break;
                                }
                            }
                            else
                            {
                                throw new AphidParserException(_currentToken);
                            }
                        }
                    }

                    Match(AphidTokenType.RightParenthesis);

                    var isSingleLine = _currentToken.TokenType != AphidTokenType.LeftBrace;

                    var body = ParseBlock(false);

                    if (isSingleLine)
                    {
                        funcExp.Body = new List<Expression> { new UnaryOperatorExpression(AphidTokenType.retKeyword, body[0]) };
                    }
                    else
                    {
                        funcExp.Body = body;
                    }

                    exp = funcExp;

                    break;

                default:

                    exp = new PartialFunctionExpression((CallExpression)ParseCallExpression());
                    break;
            }

            return exp;
        }
Example #5
0
 public AphidMacro(string name, FunctionExpression declaration, BinaryOperatorExpression originalExpression)
 {
     Name = name;
     Declaration = declaration;
     OriginalExpression = originalExpression;
 }
Example #6
0
 public AphidMacro(string name, FunctionExpression declaration, BinaryOperatorExpression originalExpression)
 {
     Name               = name;
     Declaration        = declaration;
     OriginalExpression = originalExpression;
 }
 private AphidFunction InterpretFunctionExpression(FunctionExpression expression)
 {
     return new AphidFunction()
     {
         Args = expression.Args.Select(x => x.Identifier).ToArray(),
         Body = expression.Body,
         ParentScope = _currentScope,
     };
 }
Example #8
0
 private AphidExpression ParseFunctionExpression()
 {
     AphidExpression exp = default(AphidExpression);
     var body = new System.Collections.Generic.List<AphidExpression>();
     var args = new System.Collections.Generic.List<AphidExpression>();
     AphidExpression argExp = default(AphidExpression);
     NextToken();
     if ((this._currentToken.TokenType == AphidTokenType.LeftParenthesis)) {
         NextToken();
         if (((this._currentToken.TokenType == AphidTokenType.RightParenthesis)
                     == false)) {
             for (
             ; true;
             ) {
                 if ((this._currentToken.TokenType == AphidTokenType.Identifier)) {
                     var id = ParseIdentifierExpression();
                     argExp = id;
                     if ((this._currentToken.TokenType == AphidTokenType.AssignmentOperator)) {
                         var op = this._currentToken.TokenType;
                         NextToken();
                         argExp = new BinaryOperatorExpression(id, op, ParseExpression());
                     }
                     args.Add(argExp);
                     if ((this._currentToken.TokenType == AphidTokenType.Comma)) {
                         NextToken();
                     }
                     else {
     break;
                     }
                 }
                 else {
                     throw new AphidParserException(_currentToken);
                 }
             }
         }
         Match(AphidTokenType.RightParenthesis);
         var isSingleLine = (this._currentToken.TokenType != AphidTokenType.LeftBrace);
         var block = ParseSingleBlock();
         if ((isSingleLine && UseImplicitReturns)) {
             body.Add(new UnaryOperatorExpression(AphidTokenType.retKeyword, block[0]));
         }
         else {
             body = block;
         }
         exp = new FunctionExpression(args, body);
     }
     else {
         exp = new PartialFunctionExpression(ParseCallExpression());
     }
     return exp;
 }