From 2090a4fd8ee743b7a3095c354bb0fbc14dbb1495 Mon Sep 17 00:00:00 2001 From: mrb0nk500 Date: Sat, 30 May 2020 12:43:08 -0400 Subject: Refactored the assembler a bit more, in order to remove code duplication. The assembler now uses pre-tokens, which are smaller tokens, that make up the larger tokens. --- lexer.h | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 lexer.h (limited to 'lexer.h') diff --git a/lexer.h b/lexer.h new file mode 100644 index 0000000..b8b14b0 --- /dev/null +++ b/lexer.h @@ -0,0 +1,43 @@ +static inline uint8_t isdelm(char c, uint8_t dbg) { + switch (c) { + default : return 0x00; + case '\0': + case '\n': return 0x01; + case ',' : return 0x02; + case '\"': return 0x04; + case '\'': return 0x08; + case '\t': + case ' ' : return 0x10; + } +} + +static inline uint8_t get_ptok(char c, uint8_t dbg) { + switch (c) { + case '.' : return PTOK_DOT ; + case ':' : return PTOK_COLON ; + case '=' : return PTOK_EQU ; + case '+' : return PTOK_PLUS ; + case '-' : return PTOK_MINUS ; + case '>' : return PTOK_GT ; + case '<' : return PTOK_LT ; + case '(' : return PTOK_LBRACK ; + case ')' : return PTOK_RBRACK ; + case ',' : return PTOK_COMMA ; + case 'X': case 'x' : return PTOK_X ; + case 'Y': case 'y' : return PTOK_Y ; + case '\"': return PTOK_DQUOTE ; + case '\'': return PTOK_SQUOTE ; + case '#' : return PTOK_HASH ; + case ';' : return PTOK_SCOLON ; + case '$' : return PTOK_DOLLAR ; + case '%' : return PTOK_PERCENT; + default : + if (isdigit(c)) { + return PTOK_NUMBER; + } else if (isalpha(c) || c == '_') { + return PTOK_ALPHA; + } else { + return PTOK_OTHER; + } + } +} -- cgit v1.2.3-13-gbd6f