Exemple #1
0
        public override LatteParser.TypeContext VisitEAddOp(LatteParser.EAddOpContext context)
        {
            var lhs = Visit(context.expr()[0]);
            var rhs = Visit(context.expr()[1]);

            switch (context.addOp())
            {
            case LatteParser.PlusContext _:
                if (!lhs.Equals(rhs) ||
                    (!lhs.Equals(new LatteParser.TIntContext()) && !lhs.Equals(new LatteParser.TStringContext())))
                {
                    Utils.StateUtils.InterruptWithMessage(context.start.Line, ErrorMessages.AddOpWrongType);
                }
                return(lhs);

            case LatteParser.MinusContext _:
                if (!lhs.Equals(rhs) || !lhs.Equals(new LatteParser.TIntContext()))
                {
                    Utils.StateUtils.InterruptWithMessage(context.start.Line, ErrorMessages.MinusOpToNotInt);
                }
                return(new LatteParser.TIntContext());

            default:
                throw new NotSupportedException();
            }
        }
Exemple #2
0
 public AddOp(LatteParser.EAddOpContext context) :
     base(context.expr()[0], context.expr()[1])
 {
     Add = context.addOp() switch
     {
         LatteParser.PlusContext _ => Add.Plus,
                                 LatteParser.MinusContext _ => Add.Minus
     };
 }