public override BaseType ValidateSemantic() { var leftType = LeftOperand.ValidateSemantic(); var rightType = RightOperand.ValidateSemantic(); if (leftType is IntType && rightType is IntType) { return(leftType); } throw new SemanticException($"div is not supported for {leftType} and {rightType}"); }
public override string GenerateCode() { var leftType = LeftOperand.ValidateSemantic(); var rightType = RightOperand.ValidateSemantic(); if (leftType is StringType && rightType is StringType) { return($"!({LeftOperand.GenerateCode()}.equals({RightOperand.GenerateCode()}))"); } return($"{LeftOperand.GenerateCode()} != {RightOperand.GenerateCode()}"); }
public override BaseType ValidateSemantic() { var rTipo = RightOperand.ValidateSemantic(); var lTipo = LeftOperand.ValidateSemantic(); if (Validations.ValidateReturnTypesEquivalence(rTipo, lTipo)) { return(rTipo); } throw new SemanticException($"Types don't match {rTipo} and {lTipo} at Row: {Position.Row}, Column: {Position.Column}"); }
public override string GenerateCode() { var leftType = LeftOperand.ValidateSemantic(); var rightType = RightOperand.ValidateSemantic(); if (leftType is IntType && rightType is StringType) { var count = (NumberNode)LeftOperand; var str = (StringNode)RightOperand; return($"MultiplyString({count.Value},{str.Value})"); } else if (leftType is StringType && rightType is IntType) { var str = (StringNode)LeftOperand; var count = (NumberNode)RightOperand; return($"MultiplyString({count.Value},{str.Value})"); } return($"({LeftOperand.GenerateCode()} * {RightOperand.GenerateCode()})"); }