+Literal::Literal(const vector<ScriptToken *> &s)
+: props(0)
+, script(s)
+, i1(0), i2(0)
+, i3(0), i4(0)
+, b(false)
+, type(SCRIPT) {
+
+}
+
+Literal::~Literal() {
+ switch (type) {
+ case ARRAY_VALUES:
+ for (vector<Value *>::const_iterator i(values.begin()), end(values.end()); i != end; ++i) {
+ delete *i;
+ }
+ break;
+ case ARRAY_PROPS:
+ for (vector<PropertyList *>::const_iterator i(propertyLists.begin()), end(propertyLists.end()); i != end; ++i) {
+ delete *i;
+ }
+ break;
+ case OBJECT:
+ delete props;
+ break;
+ case SCRIPT:
+ for (vector<ScriptToken *>::const_iterator i(script.begin()), end(script.end()); i != end; ++i) {
+ delete *i;
+ }
+ break;
+ default:
+ break;
+ }
+}
+
+
+const vector<Value *> &Literal::GetValues() const {
+ if (type == ARRAY_VALUES) {
+ return values;
+ } else {
+ throw runtime_error("tried to access values of non-array literal");
+ }
+}
+
+const vector<PropertyList *> &Literal::GetPropertyLists() const {
+ if (type == ARRAY_PROPS) {
+ return propertyLists;
+ } else {
+ throw runtime_error("tried to access property lists of non-array literal");
+ }
+}
+
+const vector<string> &Literal::GetIdentifiers() const {
+ if (type == ARRAY_IDENTS) {
+ return identifiers;
+ } else {
+ throw runtime_error("tried to access identifiers of non-array literal");
+ }
+}
+
+bool Literal::GetBoolean() const {
+ if (type == BOOLEAN) {
+ return b;
+ } else {
+ throw runtime_error("tried to access boolean value of non-boolean literal");
+ }
+}
+
+int Literal::GetRed() const {
+ if (type == COLOR) {
+ return i1;
+ } else {
+ throw runtime_error("tried to access red component of non-color literal");
+ }
+}
+
+int Literal::GetGreen() const {
+ if (type == COLOR) {
+ return i2;
+ } else {
+ throw runtime_error("tried to access green component of non-color literal");
+ }
+}
+
+int Literal::GetBlue() const {
+ if (type == COLOR) {
+ return i3;
+ } else {
+ throw runtime_error("tried to access blue component of non-color literal");
+ }
+}
+
+int Literal::GetAlpha() const {
+ if (type == COLOR) {
+ return i4;
+ } else {
+ throw runtime_error("tried to access alpha component of non-color literal");
+ }
+}
+
+int Literal::GetNumber() const {
+ if (type == NUMBER) {
+ return i1;
+ } else {
+ throw runtime_error("tried to access numerical value of non-number literal");
+ }
+}
+
+const string &Literal::GetString() const {
+ if (type == STRING) {
+ return str;
+ } else {
+ throw runtime_error("tried to access string value of non-color literal");
+ }
+}
+
+int Literal::GetX() const {
+ if (type == VECTOR) {
+ return i1;
+ } else {
+ throw runtime_error("tried to access x component of non-vector literal");
+ }
+}
+
+int Literal::GetY() const {
+ if (type == VECTOR) {
+ return i2;
+ } else {
+ throw runtime_error("tried to access y component of non-vector literal");
+ }
+}
+
+const string &Literal::GetTypeName() const {
+ return typeName;
+}
+
+const PropertyList *Literal::GetProperties() const {
+ if (type == OBJECT) {
+ return props;
+ } else {
+ throw runtime_error("tried to access properties of non-object literal");
+ }
+}
+
+const vector<ScriptToken *> &Literal::GetScript() const {
+ if (type == SCRIPT) {
+ return script;
+ } else {
+ throw runtime_error("tried to access script of non-script literal");
+ }
+}
+
+
+Value::~Value() {
+ if (isLiteral) {
+ delete literal;
+ }
+}
+
+const Literal &Value::GetLiteral() const {
+ if (isLiteral) {
+ return *literal;
+ } else {
+ throw runtime_error("tried to access literal of identifier value");
+ }
+}
+
+const std::string &Value::GetIdentifier() const {
+ if (!isLiteral) {
+ return identifier;
+ } else {
+ throw runtime_error("tried to access identifier of literal value");
+ }
+}
+
+
+ScriptToken::ScriptToken(const string &s, Type t)
+: literal(0)
+, str(s)
+, type(t) {
+ if (type == LITERAL) {
+ throw runtime_error("cannot create script literal without literal");
+ }
+}
+
+ScriptToken::ScriptToken(Literal *l)
+: literal(l)
+, str()
+, type(LITERAL) {
+ if (!literal) {
+ throw runtime_error("cannot create script literal without literal");
+ }
+}
+
+ScriptToken::~ScriptToken() {
+ delete literal;
+}
+
+const string &ScriptToken::RegisterName() const {
+ if (type == REGISTER) {
+ return str;
+ } else {
+ throw runtime_error("access to register name of non-register script token");
+ }
+}
+
+const string &ScriptToken::CommandName() const {
+ if (type == COMMAND) {
+ return str;
+ } else {
+ throw runtime_error("access to command name of non-command script token");
+ }
+}
+
+const string &ScriptToken::Identifier() const {
+ if (type == IDENTIFIER) {
+ return str;
+ } else {
+ throw runtime_error("access to identifier of non-identifier script token");
+ }
+}
+
+const string &ScriptToken::Label() const {
+ if (type == LABEL) {
+ return str;
+ } else {
+ throw runtime_error("access to label of non-label script token");
+ }
+}
+
+const Literal *ScriptToken::GetLiteral() const {
+ if (type == LITERAL) {
+ return literal;
+ } else {
+ throw runtime_error("access to literal value of non-literal script token");
+ }
+}
+