예제 #1
0
        private Ast.Stmt ParseIfStmt(TokenQueue q)
        {
            var stmt = new Ast.IfStmt {
                SourceToken = q.SourceToken
            };

            q.Take("if");
            stmt.Condition = ParseExpr(q);
            stmt.Block     = ParseBlock(q);
            if (q.Peek() == "else")
            {
                q.Take("else");
                stmt.ElseBlock = ParseBlock(q);
            }
            return(stmt);
        }
예제 #2
0
        private void ExecuteIfStmt(Ast.IfStmt stmt, ScriptEnv env)
        {
            var condition = EvaluateExpr <long>(stmt.Condition, env);

            if (condition == 0)
            {
                if (stmt.ElseBlock != null)
                {
                    ExecuteBlock(stmt.ElseBlock, env);
                }
            }
            else if (condition == 1)
            {
                ExecuteBlock(stmt.Block, env);
            }
            else
            {
                throw new ScriptException(
                          $"Evaluation of IF condition expression \"{stmt.Condition.Sql}\" " +
                          $"produced a value of {condition} instead of the expected 0 or 1.");
            }
        }