Exemple #1
0
 internal void SkipRestBlocks()
 {
     while (m_currentChar < m_data.Length)
     {
         int    endOfToken = m_currentChar;
         string nextToken  = Utils.GetNextToken(m_data, ref endOfToken);
         if (!ELSE_IF_LIST.Contains(nextToken) && !ELSE_LIST.Contains(nextToken))
         {
             return;
         }
         m_currentChar = endOfToken;
         SkipBlock();
     }
 }
Exemple #2
0
        internal Variable ProcessIf(ParsingScript script)
        {
            int startIfCondition = script.Pointer;

            Variable result = script.ExecuteTo(Constants.END_ARG);
            bool     isTrue = Convert.ToBoolean(result.Value);

            if (isTrue)
            {
                result = ProcessBlock(script);

                if (result.IsReturn ||
                    result.Type == Variable.VarType.BREAK ||
                    result.Type == Variable.VarType.CONTINUE)
                {
                    // We are here from the middle of the if-block. Skip it.
                    script.Pointer = startIfCondition;
                    SkipBlock(script);
                }
                SkipRestBlocks(script);

                return(result);
                //return Variable.EmptyInstance;
            }

            // We are in Else. Skip everything in the If statement.
            SkipBlock(script);

            ParsingScript nextData = new ParsingScript(script);

            string nextToken = Utils.GetNextToken(nextData);

            if (Constants.ELSE_IF_LIST.Contains(nextToken))
            {
                script.Pointer = nextData.Pointer + 1;
                result         = ProcessIf(script);
            }
            else if (Constants.ELSE_LIST.Contains(nextToken))
            {
                script.Pointer = nextData.Pointer + 1;
                result         = ProcessBlock(script);
            }

            if (result.IsReturn)
            {
                return(result);
            }
            return(Variable.EmptyInstance);
        }
Exemple #3
0
 private void SkipRestBlocks(ParsingScript script)
 {
     while (script.StillValid())
     {
         int           endOfToken = script.Pointer;
         ParsingScript nextData   = new ParsingScript(script);
         string        nextToken  = Utils.GetNextToken(nextData);
         if (Constants.ELSE_IF != nextToken &&
             Constants.ELSE != nextToken)
         {
             return;
         }
         script.Pointer = nextData.Pointer;
         SkipBlock(script);
     }
 }
Exemple #4
0
        // Прескачане на останалите блокове
        private void SkipRestBlocks(string data, ref int from)
        {
            while (from < data.Length)
            {
                int    endOfToken = from;
                string nextToken  = Utils.GetNextToken(data, ref endOfToken);
                if (!Constants.ELSE_IF_LIST.Contains(nextToken) &&
                    !Constants.ELSE_LIST.Contains(nextToken))
                {
                    return;
                }

                from = endOfToken;
                SkipBlock(data, ref from);
            }
        }
Exemple #5
0
        internal Parser.Result ProcessIf()
        {
            int startIfCondition = m_currentChar;

            Parser.Result result = null;

            Parser.Result arg1       = GetNextIfToken();
            string        comparison = Utils.GetComparison(m_data, ref m_currentChar);

            Parser.Result arg2 = GetNextIfToken();

            bool isTrue = EvalCondition(arg1, comparison, arg2);

            if (isTrue)
            {
                result = ProcessBlock();

                if (result is Continue || result is Break)
                {
                    // Got here from the middle of the if-block. Skip it.
                    m_currentChar = startIfCondition;
                    SkipBlock();
                }
                SkipRestBlocks();

                return(result);
            }

            // We are in Else. Skip everything in the If statement.
            SkipBlock();

            int    endOfToken = m_currentChar;
            string nextToken  = Utils.GetNextToken(m_data, ref endOfToken);

            if (ELSE_IF_LIST.Contains(nextToken))
            {
                m_currentChar = endOfToken + 1;
                result        = ProcessIf();
            }
            else if (ELSE_LIST.Contains(nextToken))
            {
                m_currentChar = endOfToken + 1;
                result        = ProcessBlock();
            }

            return(new Parser.Result());
        }
Exemple #6
0
        public Variable ProcessIf(string data, ref int from)
        {
            int startIfCondition = from;

            Variable result = Parser.LoadAndCalculate(data, ref from, Constants.END_ARG_ARRAY);
            bool     isTrue = Convert.ToBoolean(result.Value);

            if (isTrue)
            {
                result = ProcessBlock(data, ref from);

                if (result.Type == Variable.VarType.BREAK ||
                    result.Type == Variable.VarType.CONTINUE)
                {
                    // Имате тук от средата на блока. Пропуснете го.
                    from = startIfCondition;
                    SkipBlock(data, ref from);
                }

                SkipRestBlocks(data, ref from);

                return(result);
            }

            // Пропуснете всичко в израза "Ако".
            SkipBlock(data, ref from);

            int    endOfToken = from;
            string nextToken  = Utils.GetNextToken(data, ref endOfToken);

            if (Constants.ELSE_IF_LIST.Contains(nextToken))
            {
                from   = endOfToken + 1;
                result = ProcessIf(data, ref from);
            }
            else if (Constants.ELSE_LIST.Contains(nextToken))
            {
                from   = endOfToken + 1;
                result = ProcessBlock(data, ref from);
            }

            return(Variable.EmptyInstance);
        }
Exemple #7
0
        internal async Task <Variable> ProcessTryAsync(ParsingScript script)
        {
            int       startTryCondition = script.Pointer - 1;
            int       currentStackLevel = ParserFunction.GetCurrentStackLevel();
            Exception exception         = null;

            Variable result = null;

            bool alreadyInTryBlock = script.InTryBlock;

            script.InTryBlock = true;
            try
            {
                result = await ProcessBlockAsync(script);
            }
            catch (Exception exc)
            {
                exception = exc;
            }
            finally
            {
                script.InTryBlock = alreadyInTryBlock;
            }

            if (exception != null || result.IsReturn ||
                result.Type == Variable.VarType.BREAK ||
                result.Type == Variable.VarType.CONTINUE)
            {
                // We are here from the middle of the try-block either because
                // an exception was thrown or because of a Break/Continue. Skip it.
                script.Pointer = startTryCondition;
                SkipBlock(script);
            }

            string catchToken = Utils.GetNextToken(script);

            script.Forward(); // skip opening parenthesis
                              // The next token after the try block must be a catch.
            if (Constants.CATCH != catchToken)
            {
                throw new ArgumentException("Expecting a 'catch()' but got [" +
                                            catchToken + "]");
            }

            string exceptionName = Utils.GetNextToken(script);

            script.Forward(); // skip closing parenthesis

            if (exception != null)
            {
                string excStack = CreateExceptionStack(exceptionName, currentStackLevel);
                ParserFunction.InvalidateStacksAfterLevel(currentStackLevel);

                GetVarFunction excMsgFunc = new GetVarFunction(new Variable(exception.Message));
                ParserFunction.AddGlobalOrLocalVariable(exceptionName, excMsgFunc);
                GetVarFunction excStackFunc = new GetVarFunction(new Variable(excStack));
                ParserFunction.AddGlobalOrLocalVariable(exceptionName + ".Stack", excStackFunc);

                result = await ProcessBlockAsync(script);

                ParserFunction.PopLocalVariable(exceptionName);
            }
            else
            {
                SkipBlock(script);
            }

            SkipRestBlocks(script);
            return(result);
        }