+
+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");
+ }
+}
+