示例#1
0
        public override void EnterWhile(LatteParser.WhileContext context)
        {
            _environment.DetachVarEnv();

            var exprType = new ExpressionTypeVisitor().Visit(context.expr());

            if (!exprType.Equals(new LatteParser.TBoolContext()))
            {
                _errorState.AddErrorMessage(new ErrorMessage(
                                                context.expr().start.Line,
                                                context.expr().start.Line,
                                                ErrorMessages.WhileWrongCondition));
            }
        }
示例#2
0
        public While(LatteParser.WhileContext context)
        {
            Expr = Exprs.Utils.ExprFromExprContext(context.expr());

            var stmt = Utils.StmtFromStmtContext(context.stmt());

            Block = stmt switch
            {
                Block block => block,
                Stmt s => new Block(s)
            };
        }