Esempio n. 1
0
        public UnOp(LatteParser.EUnOpContext context)
        {
            Operator = context.unOp() switch
            {
                LatteParser.UnaryMinusContext _ => Unary.Minus,
                                              LatteParser.UnaryNegContext _ => Unary.Neg
            };

            Expr = Utils.ExprFromExprContext(context.expr());
        }
Esempio n. 2
0
        public override LatteParser.TypeContext VisitEUnOp(LatteParser.EUnOpContext context)
        {
            var expr = Visit(context.expr());

            switch (context.unOp())
            {
            case LatteParser.UnaryMinusContext _:
                if (!expr.Equals(new LatteParser.TIntContext()))
                {
                    Utils.StateUtils.InterruptWithMessage(context.start.Line, ErrorMessages.UnaryMinusToNotInt);
                }
                return(new LatteParser.TIntContext());

            case LatteParser.UnaryNegContext _:
                if (!expr.Equals(new LatteParser.TBoolContext()))
                {
                    Utils.StateUtils.InterruptWithMessage(context.start.Line, ErrorMessages.UnaryNegToNotBool);
                }
                return(new LatteParser.TBoolContext());

            default:
                throw new NotSupportedException();
            }
        }