public void Set(Variable value) { type = value.Type; boolValue = value.BoolValue; intValue = value.IntValue; stringValue = value.StringValue; }
public Variable(AST_type.AST_type_kind type) { this.type = type; this.intValue = 0; this.stringValue = ""; this.boolValue = false; }
override public void Visit(AST_identifier identifier) { if (identifier.Declaration == null) { DebugPrint("identifier: " + identifier.Name + " : not declared"); } else { if (identifier.Declaration.Type != null) { AST_type.AST_type_kind dataType = identifier.Declaration.Type.Kind; DebugPrint("identifier: " + identifier.Name + " : " + dataType.ToString()); } } }
public void Set(string value) { type = AST_type.AST_type_kind.string_type; stringValue = value; }
public void Set(int value) { type = AST_type.AST_type_kind.int_type; intValue = value; }
public void Set(bool value) { type = AST_type.AST_type_kind.bool_type; boolValue = value; }
override public void Visit(AST_binary_operator binary_operator) { base.Visit(binary_operator); if (binary_operator.LeftOperand.DataType != binary_operator.RightOperand.DataType) { Error("Left and right operands of binary operator must be of same type.", binary_operator); } else { AST_type.AST_type_kind t = binary_operator.LeftOperand.DataType; switch (binary_operator.Kind) { case Ampersand: if (t != bool_type) { Error("Binary operator '&' requires bool operands.", binary_operator); } break; case Asterisk: if (t != int_type) { Error("Binary operator '*' requires int operands.", binary_operator); } break; case Equal: // All types accepted break; case Less: // All types accepted break; case Minus: if (t != int_type) { Error("Binary operator '-' requires int operands.", binary_operator); } break; case Plus: if (t == bool_type) { Error("Binary operator '+' requires int or string operands.", binary_operator); } break; case Slash: if (t != int_type) { Error("Binary operator '/' requires int operands.", binary_operator); } break; default: break; } } switch (binary_operator.Kind) { case Equal: case Less: case Ampersand: binary_operator.DataType = bool_type; break; default: binary_operator.DataType = binary_operator.LeftOperand.DataType; break; } }