Website Summary Files Commits Branches @commit @diff @stats
path: root / src / asm / lexer.hpp
diff options
context:
space:
mode:
1 files changed, 70 insertions, 0 deletions
-rw-r--r--src/asm/lexer.hpp70
diff --git a/src/asm/lexer.hpp b/src/asm/lexer.hpp
new file mode 100644
index 0000000..ece4a07
--- /dev/null
+++ b/src/asm/lexer.hpp
@@ -0,0 +1,70 @@
+#ifndef LEXER_HPP
+#define LEXER_HPP
+
+#include <iostream>
+
+#include "token.hpp"
+
+namespace SpasmImpl
+{
+// ! Namespace for all classes and functions dealing with assembler
+namespace ASM
+{
+//! Namespace for all lexical analisys classes
+namespace Lexer
+{
+/*!
+** Class for lexers for the assembler-like language for spasm
+*/
+class Lexer
+{
+ public:
+ Lexer(std::istream&, size_t = 4096);
+ ~Lexer();
+ bool tokenize(TokenStream&);
+
+ //! fills the buffer called when the lexer needs more data
+ void read(size_t = 1);
+ void buffer_init();
+
+ private:
+ Lexer(const Lexer&);
+ Lexer& operator=(const Lexer&);
+
+ void buffer_grow(size_t);
+
+ //! input stream for the lexer
+ std::istream* file;
+
+ //! buffer for the lexer
+ char* buffer;
+
+ //! size of the buffer
+ size_t buffer_size;
+
+ //! cursor for re2c generated lexer
+ char* cursor;
+
+ //! limit for re2c generated lexer
+ char* limit;
+
+ //! marker for re2c generated lexer
+ char* marker;
+
+ //! pointer to the start of the just recognized token
+ char* token_start;
+
+ //! saves the state of the lexer
+ unsigned int state;
+
+ //! current char
+ char yych;
+
+ //! number of current line
+ size_t lineno;
+};
+} // namespace Lexer
+} // namespace ASM
+} // namespace SpasmImpl
+
+#endif