示例#1
0
    private void ExecuteWhileStmt(Ast.WhileStmt stmt, ScriptEnv env)
    {
        long condition;

        do
        {
            condition = EvaluateExpr <long>(stmt.Condition, env);
            if (condition == 1)
            {
                ExecuteBlock(stmt.Block, env);
                if (env.DidReturn)
                {
                    return;
                }
                else if (env.DidBreak)
                {
                    env.DidBreak = false;
                    break;
                }
                else if (env.DidContinue)
                {
                    env.DidContinue = false;
                }
            }
            else if (condition != 0)
            {
                throw new ScriptException(
                          $"Evaluation of WHILE condition expression \"{stmt.Condition.Sql}\" " +
                          $"produced a value of {condition} instead of the expected 0 or 1.");
            }
        } while (condition == 1);
    }
示例#2
0
    private Ast.Stmt ParseWhileStmt(TokenQueue q)
    {
        var stmt = new Ast.WhileStmt {
            SourceToken = q.SourceToken
        };

        q.Take("while");
        stmt.Condition = ParseExpr(q);
        stmt.Block     = ParseBlock(q);
        ConsumeSemicolon(q);
        return(stmt);
    }