From 93d234cd48404867b1d80a727d17a4b4a0726e1b Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Wed, 1 Nov 2023 14:38:59 +0000 Subject: Lexer now returns more descriptive tokens More useful tokens, in particular for each opcode possible. This makes parsing a simpler task to reason as now we're just checking against an enum rather than doing a string check in linear time. It makes more sense to do this at the tokeniser as the local data from the buffer will be in the cache most likely as the buffer is contiguously allocated. While it will always be slow to do linear time checks on strings, when doing it at the parser we're having to check strings that may be allocated in a variety of different places. This means caching becomes a harder task, but with this approach we're less likely to have cache misses as long as the buffer stays there. --- asm/lexer.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'asm/lexer.h') diff --git a/asm/lexer.h b/asm/lexer.h index 1e68d8b..78cf4c6 100644 --- a/asm/lexer.h +++ b/asm/lexer.h @@ -19,6 +19,26 @@ typedef enum TokenType { TOKEN_LITERAL_NUMBER, TOKEN_LITERAL_CHAR, + TOKEN_NOOP, + TOKEN_HALT, + TOKEN_PUSH, + TOKEN_POP, + TOKEN_PUSH_REG, + TOKEN_MOV, + TOKEN_DUP, + TOKEN_NOT, + TOKEN_OR, + TOKEN_AND, + TOKEN_XOR, + TOKEN_EQ, + TOKEN_LT, + TOKEN_LTE, + TOKEN_GT, + TOKEN_GTE, + TOKEN_PLUS, + TOKEN_PRINT, + TOKEN_JUMP, + TOKEN_JUMP_IF, TOKEN_SYMBOL, } token_type_t; -- cgit v1.2.3-13-gbd6f