Website Summary Files Commits Branches @commit @diff @stats
path: root / spasm / src / asm / token.hpp
diff options
context:
space:
mode:
1 files changed, 94 insertions, 0 deletions
-rw-r--r--spasm/src/asm/token.hpp94
diff --git a/spasm/src/asm/token.hpp b/spasm/src/asm/token.hpp
new file mode 100644
index 0000000..2e69108
--- /dev/null
+++ b/spasm/src/asm/token.hpp
@@ -0,0 +1,94 @@
+#ifndef TOKEN_HPP
+#define TOKEN_HPP
+
+#include <string>
+
+namespace SpasmImpl
+{
+namespace ASM
+{
+namespace Lexer
+{
+class Token
+{
+ public:
+ enum Token_type
+ {
+ _NoArgBegin,
+ Halt = _NoArgBegin,
+ Dup,
+ Pop,
+ _OneArgBegin,
+ PopTo = _OneArgBegin,
+ PushFrom,
+ Push,
+ Print,
+ Read,
+ Call,
+ Ret,
+ Jump,
+ _TwoArgBegin,
+ JumpT = _TwoArgBegin,
+ JumpF,
+ Const,
+ String,
+ _ThreeArgBegin,
+ Add = _ThreeArgBegin,
+ Sub,
+ Mul,
+ Div,
+ Mod,
+ Less,
+ LessEq,
+ _NotOpCodeBegin,
+ Label = _NotOpCodeBegin,
+ Ident,
+ // Register,
+ Integer,
+ XInteger,
+ FloatingPoint,
+ StringValue,
+ EndInput,
+ NotUsed
+ };
+
+ Token(Token_type = NotUsed);
+
+ Token(Token_type, size_t, const char* = NULL, const char* = NULL);
+
+ Token_type type() const;
+
+ size_t lineno() const;
+
+ int64_t value_int() const;
+ void set_int(int64_t v) { _value_int = v; }
+
+ double value_double() const { return _value_double; }
+
+ const std::string& value_str() const;
+
+ private:
+ Token_type _type;
+
+ size_t _lineno;
+
+ int64_t _value_int;
+ double _value_double;
+
+ 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