Ejemplo n.º 1
0
        public override void CheckSemantics(Scope scope, List <SemanticError> errors)
        {
            LeftOperand.CheckSemantics(scope, errors);
            RightOperand.CheckSemantics(scope, errors);

            if (errors.Any())
            {
                return;
            }

            if (!SupportType(LeftOperand.Type))
            {
                errors.Add(SemanticError.InvalidUseOfOperator("binary relational", "valid", "left", LeftOperand));
            }

            if (!SupportType(RightOperand.Type))
            {
                errors.Add(SemanticError.InvalidUseOfOperator("binary relational", "valid", "right", RightOperand));
            }

            if (RightOperand.Type != LeftOperand.Type)
            {
                errors.Add(new SemanticError
                {
                    Message = "Types of left and right operands of the binary relational operator do not match",
                    Node    = this
                });
            }

            if (LeftOperand.Type.Equals(Types.Nil) && RightOperand.Type.Equals(Types.Nil))
            {
                errors.Add(new SemanticError
                {
                    Message = $"Types of left and right operands of the binary relational operator can't be both '{Types.Nil}'",
                    Node    = this
                });
            }

            if (LeftOperand is ComparisonNode || RightOperand is ComparisonNode)
            {
                errors.Add(new SemanticError
                {
                    Message = "Comparison operators do not associate",
                    Node    = this
                });
            }
        }
Ejemplo n.º 2
0
        public override void CheckSemantics(Scope scope, List <SemanticError> errors)
        {
            LeftOperand.CheckSemantics(scope, errors);
            RightOperand.CheckSemantics(scope, errors);

            if (LeftOperand.Type != Type)
            {
                errors.Add(SemanticError.InvalidUseOfOperator(
                               "binary logical", LeftOperand.Type.Equals(Types.Nil) ? "valued" : "integer", "left", LeftOperand));
            }

            if (RightOperand.Type != Type)
            {
                errors.Add(SemanticError.InvalidUseOfOperator(
                               "binary logical", RightOperand.Type.Equals(Types.Nil) ? "valued" : "integer", "right", RightOperand));
            }
        }
Ejemplo n.º 3
0
        public override void CheckSemantics(Scope scope, Report report)
        {
            LeftOperand.CheckSemantics(scope, report);
            RightOperand.CheckSemantics(scope, report);

            //No tener errores en los operandos
            if (LeftOperand.returnType.isError || RightOperand.returnType.isError)
            {
                returnType = scope.FindType("error");
                return;
            }

            //Verificar que sean del mismo tipo
            if (!LeftOperand.returnType.Alike(RightOperand.returnType))
            {
                report.Add(LeftOperand.Line, LeftOperand.CharPositionInLine, string.Format("Can't apply operator {0} between types {1} and {2}", Text, LeftOperand.returnType.name, RightOperand.returnType.name));
                returnType = scope.FindType("error");
                return;
            }

            returnType = LeftOperand.returnType;
        }