Website Summary Files Commits Branches @commit @diff @stats
path: root / spasm / src / asm / token.hpp
diff options
context:
space:
mode:
Commitc3252e63c296d1133254f4973fe7e3bf52cc6c1a (patch)
Author
 Dimitar Trendafilov <dimitar@coherent-labs.com>
2018-11-05 23:34:00 +0200
Committer
 Dimitar Trendafilov <dimitar@coherent-labs.com>
2018-11-05 23:34:00 +0200
Files67c6bfc067696562aded70f66d25899f3f70a1c8 /spasm/src/asm/token.hpp
IPL-c3252e63c296d1133254f4973fe7e3bf52cc6c1a.tar
IPL-c3252e63c296d1133254f4973fe7e3bf52cc6c1a.tar.gz
IPL-c3252e63c296d1133254f4973fe7e3bf52cc6c1a.zip
Parentc9912fdb174e1580629e00cacab6bc4ed480e643 (diff)
Parent6e19bb560d474736d45f5be011ff0830c7019991 (diff)
Merge commit '6e19bb560d474736d45f5be011ff0830c7019991' as 'spasm'
1 files changed, 85 insertions, 0 deletions
-rw-r--r--spasm/src/asm/token.hpp85
diff --git a/spasm/src/asm/token.hpp b/spasm/src/asm/token.hpp
new file mode 100644
index 0000000..4ef7ce0
--- /dev/null
+++ b/spasm/src/asm/token.hpp
@@ -0,0 +1,85 @@
+#ifndef TOKEN_HPP
+#define TOKEN_HPP
+
+#include <string>
+
+#define TOKENS \
+ TOK(push) \
+ TOK(pop) \
+ TOK(dup) \
+ TOK(print) \
+ TOK(read) \
+ TOK(plus) \
+ TOK(minus) \
+ TOK(multiply) \
+ TOK(divide) \
+ TOK(modulus) \
+ TOK(gotrue) \
+ TOK(gofalse) \
+ TOK(go) \
+ TOK(call) \
+ TOK(ret) \
+ TOK(load) \
+ TOK(store) \
+ TOK(less) \
+ TOK(lesseq) \
+ TOK(label) \
+ TOK(ident) \
+ TOK(integer) \
+ TOK(xinteger) \
+ TOK(endinput)
+
+namespace SpasmImpl
+{
+namespace ASM
+{
+namespace Lexer
+{
+class Token
+{
+ public:
+ enum Token_type
+ {
+ halt = 0,
+#define TOK(x) x,
+ TOKENS
+#undef TOK
+ notused
+ };
+
+ Token(Token_type = notused);
+
+ Token(Token_type, size_t, const char* = NULL, const char* = NULL);
+
+ Token_type type() const;
+
+ size_t lineno() const;
+
+ int value_int() const;
+
+ const std::string& value_str() const;
+
+ private:
+ Token_type _type;
+
+ size_t _lineno;
+
+ int _value_int;
+
+ std::string _value_str;
+};
+
+class TokenStream
+{
+ public:
+ virtual void push_token(const Token&) = 0;
+ virtual ~TokenStream(){};
+};
+
+} // namespace Lexer
+} // namespace ASM
+} // namespace SpasmImpl
+
+#undef TOKENS
+
+#endif