public override CustomType EvaluateSemantic()
        {
            var leftType  = LeftOperand.EvaluateSemantic();
            var rightType = RightOperand.EvaluateSemantic();

            var key = new Tuple <CustomType, CustomType>(leftType, rightType);

            if (!OperatorRules.ContainsKey(key))
            {
                throw new SemanticException($"Opperation Rule Not Supported  between {leftType} and {rightType}");
            }
            return(OperatorRules[key]);
        }
Пример #2
0
        public override Tipo EvaluateSemantic()
        {
            var ltipo = LeftOperand.EvaluateSemantic();
            var rtipo = RightOperand.EvaluateSemantic();

            if (ltipo.GetType() == rtipo.GetType())
            {
                if (ltipo is IntTipo)
                {
                    return(ltipo);
                }
            }
            throw new SemanticException($"No se puede dividir entre tipo: {ltipo} y {rtipo}");
        }
        public override ExpressionCode GenerateCode()
        {
            var leftType  = LeftOperand.EvaluateSemantic();
            var rightType = RightOperand.EvaluateSemantic();

            if (leftType != null && rightType != null)
            {
                var stringCode = "( getIntLeftShiftValue( " + LeftOperand.GenerateCode().Code + " , " +
                                 RightOperand.GenerateCode().Code + " ) )";
                return(new ExpressionCode {
                    Code = stringCode, Type = "int"
                });
            }
            throw new GenerationException("Cannot generate code from null type operand");
        }
Пример #4
0
        public override Tipo EvaluateSemantic()
        {
            var ltipo = LeftOperand.EvaluateSemantic();
            var rtipo = RightOperand.EvaluateSemantic();

            if (ltipo.GetType() != rtipo.GetType())
            {
                throw new SemanticException($"No se puede sumar entre tipo: {ltipo} y {rtipo}");
            }
            if (ltipo is IntTipo || ltipo is StringTipo || ltipo is BoolTipo)
            {
                return(ltipo);
            }
            throw new SemanticException($"No se puede sumar entre tipo: {ltipo} y {rtipo}");
        }