public override DataType staticTypeCheck() { DataType leftType = LeftOperand.staticTypeCheck(); DataType rightType = RightOperand.staticTypeCheck(); if (leftType == DataType.StringType || rightType == DataType.StringType) { Log.Error(String.Format("Type mismatch - {0}->{1}", leftType.ToString(), rightType.ToString()), Filename, Line, Position); } if (leftType == DataType.FloatType || rightType == DataType.FloatType) { if (leftType == DataType.IntegerType) { Log.Warning("Implicit IntType->FloatType cast", Filename, Line, Position); TypeCastNode castNode = new TypeCastNode(DataType.FloatType, LeftOperand, LeftOperand.Filename, LeftOperand.Line, LeftOperand.Position); LeftOperand = castNode; } if (rightType == DataType.IntegerType) { Log.Warning("Implicit IntType->FloatType cast", Filename, Line, Position); TypeCastNode castNode = new TypeCastNode(DataType.FloatType, RightOperand, RightOperand.Filename, RightOperand.Line, RightOperand.Position); RightOperand = castNode; } return(DataType.FloatType); } return(DataType.IntegerType); }
private bool castOperator() { int line = _line; int position = _position; if (!accept("<")) { return(false); } string type = oneOf(_dataTypes); if (type == null) { Log.Error("Expected type", _filename, line, position); } expect(">"); DataType dataType = _dataTypeMapping[type]; TypeCastNode node = new TypeCastNode(dataType, null, _filename, line, position); _stack.Push(node); return(true); }