Exemple #1
0
        public override Tuple <ABT.Env, ABT.Stmt> GetStmt(ABT.Env env)
        {
            Option <ABT.Expr> init = this.Init.Map(_ => _.GetExpr(env));

            if (init.IsSome)
            {
                env = init.Value.Env;
            }

            Option <ABT.Expr> cond = this.Cond.Map(_ => _.GetExpr(env));

            if (cond.IsSome)
            {
                env = cond.Value.Env;
            }

            if (cond.IsSome && !cond.Value.Type.IsScalar)
            {
                throw new InvalidOperationException("Error: conditional expression in while Loop must be scalar.");
            }

            Option <ABT.Expr> loop = this.Loop.Map(_ => _.GetExpr(env));

            if (loop.IsSome)
            {
                env = loop.Value.Env;
            }

            Tuple <ABT.Env, ABT.Stmt> r_body = this.Body.GetStmt(env);

            env = r_body.Item1;
            ABT.Stmt body = r_body.Item2;

            return(new Tuple <ABT.Env, ABT.Stmt>(env, new ABT.ForStmt(init, cond, loop, body)));
        }
Exemple #2
0
        public override Tuple <ABT.Env, ABT.Stmt> GetStmt(ABT.Env env)
        {
            ABT.Expr expr = this.Expr.GetExpr(env);

            Tuple <ABT.Env, ABT.Stmt> r_stmt = this.Stmt.GetStmt(env);

            env = r_stmt.Item1;
            ABT.Stmt stmt = r_stmt.Item2;

            return(new Tuple <ABT.Env, ABT.Stmt>(env, new ABT.SwitchStmt(expr, stmt)));
        }
Exemple #3
0
        public override Tuple <ABT.Env, ABT.Stmt> GetStmt(ABT.Env env)
        {
            ABT.Expr cond = this.Cond.GetExpr(env);

            if (!cond.Type.IsScalar)
            {
                throw new InvalidOperationException("Error: expected scalar Type");
            }

            Tuple <ABT.Env, ABT.Stmt> r_stmt = this.Stmt.GetStmt(env);

            env = r_stmt.Item1;
            ABT.Stmt stmt = r_stmt.Item2;

            return(new Tuple <ABT.Env, ABT.Stmt>(env, new ABT.IfStmt(cond, stmt)));
        }
Exemple #4
0
        public override Tuple <ABT.Env, ABT.Stmt> GetStmt(ABT.Env env)
        {
            Tuple <ABT.Env, ABT.Stmt> r_body = this.Body.GetStmt(env);

            env = r_body.Item1;
            ABT.Stmt body = r_body.Item2;

            ABT.Expr cond = this.Cond.GetExpr(env);
            env = cond.Env;

            if (!cond.Type.IsScalar)
            {
                throw new InvalidOperationException("Error: conditional expression in while Loop must be scalar.");
            }

            return(new Tuple <ABT.Env, ABT.Stmt>(env, new ABT.DoWhileStmt(body, cond)));
        }