Пример #1
0
        public static TryExpression Create(
            AphidExpressionContext context_aphidExpressionContext,
            List <AphidExpression> tryBody_list,
            IdentifierExpression catchArg_identifierExpression,
            List <AphidExpression> catchBody_list1,
            List <AphidExpression> finallyBody_list2,
            int value_i,
            int value_i1
            )
        {
            TryExpression tryExpression
                = new TryExpression(context_aphidExpressionContext, tryBody_list,
                                    catchArg_identifierExpression, catchBody_list1, finallyBody_list2);

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

            // TODO: Edit factory method of TryExpression
            // 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.
        }
Пример #2
0
        private Expression ParseTryExpression()
        {
            NextToken();
            var tryExp = new TryExpression()
            {
                TryBody = ParseBlock()
            };

            switch (_currentToken.TokenType)
            {
            case AphidTokenType.catchKeyword:
                NextToken();
                Match(AphidTokenType.LeftParenthesis);
                tryExp.CatchArg = ParseIdentifierExpression();
                Match(AphidTokenType.RightParenthesis);
                tryExp.CatchBody = ParseBlock();

                if (_currentToken.TokenType == AphidTokenType.finallyKeyword)
                {
                    NextToken();
                    tryExp.FinallyBody = ParseBlock();
                }

                break;

            case AphidTokenType.finallyKeyword:
                NextToken();
                tryExp.FinallyBody = ParseBlock();
                break;

            default:
                throw new AphidParserException(_currentToken);
            }

            return(tryExp);
        }
Пример #3
0
 private void InterpretFinallyBlock(TryExpression expression)
 {
     EnterChildScope();
     Interpret(expression.FinallyBody, false);
     LeaveChildScope(false);
 }
Пример #4
0
 private void InterpretCatchBlock(TryExpression expression, Exception e)
 {
     LeaveChildScope(true);
     EnterChildScope();
     _currentScope.Add(
         expression.CatchArg.Identifier,
         new AphidObject(e.Message));
     Interpret(expression.CatchBody, false);
     LeaveChildScope(true);
 }
Пример #5
0
 private void InterpretTryExpression(TryExpression expression)
 {
     if (expression.FinallyBody == null)
     {
         try
         {
             InterpretTryBlock(expression);
         }
         catch (Exception e)
         {
             InterpretCatchBlock(expression, e);
         }
     }
     else if (expression.CatchBody != null)
     {
         try
         {
             InterpretTryBlock(expression);
         }
         catch (Exception e)
         {
             InterpretCatchBlock(expression, e);
         }
         finally
         {
             InterpretFinallyBlock(expression);
         }
     }
     else
     {
         try
         {
             InterpretTryBlock(expression);
         }
         finally
         {
             InterpretFinallyBlock(expression);
         }
     }
 }
Пример #6
0
 private void InterpretTryBlock(TryExpression expression)
 {
     EnterChildScope();
     Interpret(expression.TryBody, false);
     LeaveChildScope(true);
 }
Пример #7
0
        private AphidExpression ParseTryExpression()
        {
            NextToken();
            var tryExp = new TryExpression() { TryBody = ParseBlock() };

            switch (_currentToken.TokenType)
            {
                case AphidTokenType.catchKeyword:
                    NextToken();
                    Match(AphidTokenType.LeftParenthesis);
                    tryExp.CatchArg = ParseIdentifierExpression();
                    Match(AphidTokenType.RightParenthesis);
                    tryExp.CatchBody = ParseBlock();

                    if (_currentToken.TokenType == AphidTokenType.finallyKeyword)
                    {
                        NextToken();
                        tryExp.FinallyBody = ParseBlock();
                    }

                    break;

                case AphidTokenType.finallyKeyword:
                    NextToken();
                    tryExp.FinallyBody = ParseBlock();
                    break;

                default:
                    throw new AphidParserException(_currentToken);
            }

            return tryExp;
        }