Пример #1
0
        public override void TypeCheck()
        {
            lhs.TypeCheck();
            rhs.TypeCheck();

            switch (op)
            {
            case '<':
                if (!lhs.type.Compatible(rhs.type))
                {
                    Console.Error.WriteLine("invalid arguments for less than expression\n");
                    throw new Exception("TypeCheck error");
                }
                type = new BoolType();
                break;

            case '+':
                if (!lhs.type.Compatible(rhs.type))
                {
                    Console.Error.WriteLine("invalid arguments for addition expression\n");
                    throw new Exception("TypeCheck error");
                }
                type = new IntType();
                break;

            case '*':
                if (!lhs.type.Compatible(rhs.type))
                {
                    Console.Error.WriteLine("invalid arguments for multiplication expression\n");
                    throw new Exception("TypeCheck error");
                }
                type = new IntType();
                break;

            case '-':
                if (!lhs.type.Compatible(rhs.type))
                {
                    Console.Error.WriteLine("invalid arguments for subtraction expression\n");
                    throw new Exception("TypeCheck error");
                }
                type = new IntType();
                break;

            default:
                Console.Error.WriteLine("Unexpected binary operator '%c'\n", op);
                throw new Exception("TypeCheck error");
            }
        }
Пример #2
0
 public override void TypeCheck()
 {
     type = new IntType();
 }