Added Type class, bettered types a bit, made address of and dereference operators work.

This commit is contained in:
Nathan Braswell
2013-12-23 01:26:24 -06:00
parent 935cc6f968
commit 15674fec2a
10 changed files with 207 additions and 106 deletions

View File

@@ -4,12 +4,12 @@ ASTData::ASTData() {
this->type = undef;
}
ASTData::ASTData(ASTType type, ValueType valueType) {
ASTData::ASTData(ASTType type, Type valueType) {
this->type = type;
this->valueType = valueType;
}
ASTData::ASTData(ASTType type, Symbol symbol, ValueType valueType) {
ASTData::ASTData(ASTType type, Symbol symbol, Type valueType) {
this->type = type;
this->valueType = valueType;
this->symbol = symbol;
@@ -20,44 +20,7 @@ ASTData::~ASTData() {
}
std::string ASTData::toString() {
return ASTTypeToString(type) + (symbol.isTerminal() ? " " + symbol.toString() : "") + (valueType ? " " + ValueTypeToString(valueType) : "");
}
ValueType ASTData::strToType(std::string type) {
if (type == "void")
return void_type;
else if (type == "bool")
return boolean;
else if (type == "int")
return integer;
else if (type == "float")
return floating;
else if (type == "double")
return double_percision;
else if (type == "string")
return char_string;
else return none;
}
std::string ASTData::ValueTypeToString(ValueType type) {
switch (type) {
case none:
return "none";
case void_type:
return "void";
case boolean:
return "bool";
case integer:
return "int";
case floating:
return "float";
case double_percision:
return "double";
case char_string:
return "string";
default:
return "unknown_ValueType";
}
return ASTTypeToString(type) + (symbol.isTerminal() ? " " + symbol.toString() : "") + " " + valueType.toString();
}
std::string ASTData::ASTTypeToString(ASTType type) {