Website Summary Files Commits Branches @commit @diff @stats
path: root / spasm / src / asm / token.cpp
diff options
context:
space:
mode:
1 files changed, 65 insertions, 0 deletions
-rw-r--r--spasm/src/asm/token.cpp65
diff --git a/spasm/src/asm/token.cpp b/spasm/src/asm/token.cpp
new file mode 100644
index 0000000..6c88bef
--- /dev/null
+++ b/spasm/src/asm/token.cpp
@@ -0,0 +1,65 @@
+#include <memory>
+#include <new>
+#include <queue>
+#include <string>
+
+#include "token.hpp"
+
+namespace SpasmImpl
+{
+namespace ASM
+{
+namespace Lexer
+{
+Token::Token(Token_type type)
+ : _type(type), _lineno(0), _value_int(0), _value_str("")
+{
+}
+
+Token::Token(Token::Token_type type,
+ size_t lineno,
+ const char* start,
+ const char* end)
+ : _type(type), _lineno(lineno)
+{
+ if (_type == integer || _type == xinteger)
+ {
+ _value_int = strtol(start, NULL, 0);
+ }
+ else if (_type == ident)
+ {
+ if (end)
+ {
+ _value_str = std::string(start, end);
+ }
+ else
+ {
+ _value_str = std::string(start);
+ }
+ }
+}
+
+Token::Token_type Token::type() const
+{
+ return _type;
+}
+
+int Token::value_int() const
+{
+ return _value_int;
+}
+
+const std::string& Token::value_str() const
+{
+ return _value_str;
+}
+
+size_t Token::lineno() const
+{
+ return _lineno;
+}
+
+} // namespace Lexer
+
+} // namespace ASM
+} // namespace SpasmImpl