Esempio n. 1
0
 private AphidExpression ParseArrayAccessExpression()
 {
     var exp = ParseCallExpression();
     for (
     ; (this._currentToken.TokenType == AphidTokenType.LeftBracket);
     ) {
         NextToken();
         var key = ParseExpression();
         Match(AphidTokenType.RightBracket);
         exp = new ArrayAccessExpression(exp, key);
     }
     return exp;
 }
Esempio n. 2
0
        public Expression ParseArrayAccessExpression()
        {
            var exp = ParseCallExpression();

            while (_currentToken.TokenType == AphidTokenType.LeftBracket)
            {
                NextToken();
                var key = ParseExpression();
                Match(AphidTokenType.RightBracket);
                exp = new ArrayAccessExpression(exp, key);
            }

            return(exp);
        }
Esempio n. 3
0
        public Expression ParseArrayAccessExpression()
        {
            var exp = ParseCallExpression();

            while (_currentToken.TokenType == AphidTokenType.LeftBracket)
            {
                NextToken();
                var key = ParseExpression();
                Match(AphidTokenType.RightBracket);
                exp = new ArrayAccessExpression(exp, key);
            }

            return exp;
        }
        public static ArrayAccessExpression Create(
            AphidExpressionContext context_aphidExpressionContext,
            AphidExpression arrayExpression_aphidExpression,
            List <AphidExpression> keyExpressions_list,
            int value_i,
            int value_i1
            )
        {
            ArrayAccessExpression arrayAccessExpression
                = new ArrayAccessExpression(context_aphidExpressionContext,
                                            arrayExpression_aphidExpression, keyExpressions_list);

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

            // TODO: Edit factory method of ArrayAccessExpression
            // 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.
        }
Esempio n. 5
0
        public Expression ParseFactor()
        {
            Expression exp;

            switch (_currentToken.TokenType)
            {
            case AphidTokenType.LeftBrace:
                exp = ParseObjectExpression();
                break;

            case AphidTokenType.LeftBracket:
                exp = ParseArrayExpression();
                break;

            case AphidTokenType.LeftParenthesis:
                NextToken();
                exp = ParseExpression();
                Match(AphidTokenType.RightParenthesis);
                break;

            case AphidTokenType.String:
                exp = ParseStringExpression();
                break;

            case AphidTokenType.Number:
                exp = ParseNumberExpression();
                break;

            case AphidTokenType.Identifier:
                exp = ParseIdentifierExpression();
                break;

            case AphidTokenType.functionOperator:
                exp = ParseFunctionExpression();
                break;

            case AphidTokenType.forKeyword:
                exp = ParseForExpression();
                break;

            case AphidTokenType.retKeyword:
                exp = ParseReturnExpression();
                break;

            case AphidTokenType.trueKeyword:
                exp = new BooleanExpression(true);
                NextToken();
                break;

            case AphidTokenType.falseKeyword:
                exp = new BooleanExpression(false);
                NextToken();
                break;

            case AphidTokenType.thisKeyword:
                exp = new ThisExpression();
                NextToken();
                break;

            case AphidTokenType.ifKeyword:
                exp = ParseIfExpression();
                break;

            case AphidTokenType.LoadScriptOperator:
                exp = ParseLoadScriptExpression();
                break;

            case AphidTokenType.LoadLibraryOperator:
                exp = ParseLoadLibraryExpression();
                break;

            case AphidTokenType.nullKeyword:
                exp = new NullExpression();
                NextToken();
                break;

            case AphidTokenType.breakKeyword:
                exp = new BreakExpression();
                NextToken();
                break;

            case AphidTokenType.HexNumber:
                exp = new NumberExpression((decimal)Convert.ToInt64(_currentToken.Lexeme.Substring(2), 16));
                NextToken();
                break;

            default:
                throw new AphidParserException(_currentToken);
            }

            switch (_currentToken.TokenType)
            {
            case AphidTokenType.LeftBracket:
                if (exp is ArrayExpression)
                {
                    break;
                }

                NextToken();
                var key = ParseExpression();
                Match(AphidTokenType.RightBracket);
                exp = new ArrayAccessExpression(exp, key);
                break;
            }

            return(exp);
        }
        public Expression ParseFactor()
        {
            Expression exp;
            switch (_currentToken.TokenType)
            {
                case AphidTokenType.LeftBrace:
                    exp = ParseObjectExpression();
                    break;

                case AphidTokenType.LeftBracket:
                    exp = ParseArrayExpression();
                    break;

                case AphidTokenType.LeftParenthesis:
                    NextToken();
                    exp = ParseExpression();
                    Match(AphidTokenType.RightParenthesis);
                    break;

                case AphidTokenType.String:
                    exp = ParseStringExpression();
                    break;

                case AphidTokenType.Number:
                    exp = ParseNumberExpression();
                    break;

                case AphidTokenType.Identifier:
                    exp = ParseIdentifierExpression();
                    break;

                case AphidTokenType.functionOperator:
                    exp = ParseFunctionExpression();
                    break;

                case AphidTokenType.forKeyword:
                    exp = ParseForExpression();
                    break;

                case AphidTokenType.retKeyword:
                    exp = ParseReturnExpression();
                    break;

                case AphidTokenType.trueKeyword:
                    exp = new BooleanExpression(true);
                    NextToken();
                    break;

                case AphidTokenType.falseKeyword:
                    exp = new BooleanExpression(false);
                    NextToken();
                    break;

                case AphidTokenType.thisKeyword:
                    exp = new ThisExpression();
                    NextToken();
                    break;

                case AphidTokenType.ifKeyword:
                    exp = ParseIfExpression();
                    break;

                case AphidTokenType.LoadScriptOperator:
                    exp = ParseLoadScriptExpression();
                    break;

                case AphidTokenType.LoadLibraryOperator:
                    exp = ParseLoadLibraryExpression();
                    break;

                case AphidTokenType.nullKeyword:
                    exp = new NullExpression();
                    NextToken();
                    break;

                case AphidTokenType.breakKeyword:
                    exp = new BreakExpression();
                    NextToken();
                    break;

                case AphidTokenType.HexNumber:
                    exp = new NumberExpression((decimal)Convert.ToInt64(_currentToken.Lexeme.Substring(2), 16));
                    NextToken();
                    break;

                default:
                    throw new AphidParserException(_currentToken);
            }

            switch (_currentToken.TokenType)
            {
                case AphidTokenType.LeftBracket:
                    if (exp is ArrayExpression)
                    {
                        break;
                    }

                    NextToken();
                    var key = ParseExpression();
                    Match(AphidTokenType.RightBracket);
                    exp = new ArrayAccessExpression(exp, key);
                    break;
            }

            return exp;
        }
        private AphidObject InterpretArrayAccessExpression(ArrayAccessExpression expression)
        {
            var val = ValueHelper.Unwrap(InterpretExpression(expression.ArrayExpression));
            var index = Convert.ToInt32(ValueHelper.Unwrap(InterpretExpression(expression.KeyExpression)));
            var array = val as List<AphidObject>;
            string str;

            if (array != null)
            {
                return array[index];
            }
            else if ((str = val as string) != null)
            {
                return CallInitFunction(new AphidObject(str[index].ToString()));
            }
            else
            {
                throw new AphidRuntimeException("Array access not supported by {0}.", val);
            }
        }
Esempio n. 8
0
 private CodeExpression GenerateImperativeExpression(ArrayAccessExpression node)
 {
     return new CodeArrayIndexerExpression(
         GenerateImperativeExpression(node.ArrayExpression),
         GenerateImperativeExpression(node.KeyExpression));
 }