コード例 #1
0
ファイル: Interpreter.cs プロジェクト: shincar/cscs
        private async Task <Variable> ProcessBlockAsync(ParsingScript script)
        {
            int      blockStart = script.Pointer;
            Variable result     = null;

            if (script.Debugger != null)
            {
                bool done = false;
                result = await script.Debugger.DebugBlockIfNeeded(script, done, (newDone) => { done = newDone; });

                if (done)
                {
                    return(result);
                }
            }
            while (script.StillValid())
            {
                int endGroupRead = script.GoToNextStatement();
                if (endGroupRead > 0 || !script.StillValid())
                {
                    return(result != null ? result : new Variable());
                }

                result = await script.ExecuteToAsync();

                if (result.IsReturn ||
                    result.Type == Variable.VarType.BREAK ||
                    result.Type == Variable.VarType.CONTINUE)
                {
                    return(result);
                }
            }
            return(result);
        }
コード例 #2
0
ファイル: Interpreter.cs プロジェクト: shincar/cscs
        public async Task <Variable> ProcessAsync(string script, string filename = "", bool mainFile = false)
        {
            Dictionary <int, int> char2Line;
            string data = Utils.ConvertToScript(script, out char2Line, filename);

            if (string.IsNullOrWhiteSpace(data))
            {
                return(null);
            }

            ParsingScript toParse = new ParsingScript(data, 0, char2Line);

            toParse.OriginalScript = script;
            toParse.Filename       = filename;

            if (mainFile)
            {
                toParse.MainFilename = toParse.Filename;
            }

            Variable result = null;

            while (toParse.Pointer < data.Length)
            {
                result = await toParse.ExecuteToAsync();

                toParse.GoToNextStatement();
            }

            return(result);
        }
コード例 #3
0
ファイル: Interpreter.cs プロジェクト: shincar/cscs
        internal async Task <Variable> ProcessIfAsync(ParsingScript script)
        {
            int startIfCondition = script.Pointer;

            Variable result = await script.ExecuteToAsync(Constants.END_ARG);

            bool isTrue = Convert.ToBoolean(result.Value);

            if (isTrue)
            {
                result = await ProcessBlockAsync(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);

            nextData.ParentScript = script;

            string nextToken = Utils.GetNextToken(nextData);

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

            if (result.IsReturn)
            {
                return(result);
            }
            return(Variable.EmptyInstance);
        }
コード例 #4
0
        public static async Task <List <Variable> > GetArrayIndicesAsync(ParsingScript script, string varName, int end, Action <string, int> updateVals)
        {
            List <Variable> indices = new List <Variable>();

            int argStart = varName.IndexOf(Constants.START_ARRAY);

            if (argStart < 0)
            {
                return(indices);
            }
            int firstIndexStart = argStart;

            while (argStart < varName.Length &&
                   varName[argStart] == Constants.START_ARRAY)
            {
                int argEnd = varName.IndexOf(Constants.END_ARRAY, argStart + 1);
                if (argEnd == -1 || argEnd <= argStart + 1)
                {
                    break;
                }

                ParsingScript tempScript = script.GetTempScript(varName, argStart);

                /*ParsingScript tempScript = new ParsingScript(varName, argStart);
                 * tempScript.ParentScript = script;
                 * tempScript.Char2Line = script.Char2Line;
                 * tempScript.Filename = script.Filename;
                 * tempScript.OriginalScript = script.OriginalScript;
                 * tempScript.InTryBlock = script.InTryBlock;*/

                tempScript.MoveForwardIf(Constants.START_ARG, Constants.START_ARRAY);

                Variable index = await tempScript.ExecuteToAsync(Constants.END_ARRAY);

                indices.Add(index);
                argStart = argEnd + 1;
            }

            if (indices.Count > 0)
            {
                varName = varName.Substring(0, firstIndexStart);
                end     = argStart - 1;
            }

            updateVals(varName, end);
            return(indices);
        }
コード例 #5
0
ファイル: Interpreter.cs プロジェクト: shincar/cscs
        internal async Task <Variable> ProcessWhileAsync(ParsingScript script)
        {
            int startWhileCondition = script.Pointer;

            // A check against an infinite loop.
            int  cycles     = 0;
            bool stillValid = true;

            while (stillValid)
            {
                script.Pointer = startWhileCondition;

                //int startSkipOnBreakChar = from;
                Variable condResult = await script.ExecuteToAsync(Constants.END_ARG);

                stillValid = Convert.ToBoolean(condResult.Value);
                if (!stillValid)
                {
                    break;
                }

                // Check for an infinite loop if we are comparing same values:
                if (MAX_LOOPS > 0 && ++cycles >= MAX_LOOPS)
                {
                    throw new ArgumentException("Looks like an infinite loop after " +
                                                cycles + " cycles.");
                }

                Variable result = await ProcessBlockAsync(script);

                if (result.IsReturn || result.Type == Variable.VarType.BREAK)
                {
                    script.Pointer = startWhileCondition;
                    break;
                }
            }

            // The while condition is not true anymore: must skip the whole while
            // block before continuing with next statements.
            SkipBlock(script);
            return(Variable.EmptyInstance);
        }