aboutsummaryrefslogtreecommitdiff
path: root/src/as_tokenizer.h
diff options
context:
space:
mode:
authorMistivia <i@mistivia.com>2025-02-21 18:57:46 +0800
committerMistivia <i@mistivia.com>2025-02-21 18:58:09 +0800
commitb747628cbfba50fe3d74f7b8ed316d0bd2d56bdc (patch)
tree3fcc7cdb5285b80d02957136a87e96ced06eaa8d /src/as_tokenizer.h
parent0f310a7f7ba2c3db3e36de1b9068a34f46ee5b17 (diff)
new assembler: tokenizer
Diffstat (limited to 'src/as_tokenizer.h')
-rw-r--r--src/as_tokenizer.h36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/as_tokenizer.h b/src/as_tokenizer.h
new file mode 100644
index 0000000..fef8625
--- /dev/null
+++ b/src/as_tokenizer.h
@@ -0,0 +1,36 @@
+#include <stdint.h>
+#include <stdio.h>
+
+typedef enum {
+ OP, ARG, LABEL, COLON, NEWLINE, ENDOFFILE
+} TokenType;
+
+typedef struct {
+ TokenType type;
+ int line;
+ int col;
+ char *sval;
+ int64_t ival;
+ double fval;
+} Token;
+
+#define INPUT_STREAM_BUF_SIZE 1024
+
+typedef struct {
+ FILE *fp;
+ char *buf;
+ int buf_pos;
+ int cursor;
+ int line;
+ int col;
+} InputStream;
+
+typedef struct {
+ Token* buf;
+ InputStream *s;
+} TokenStream;
+
+Token *nextToken(TokenStream *ts);
+Token *peekToken(TokenStream *ts);
+void printToken(Token *t);
+TokenStream* makeTokenStream(FILE* fp);