diff options
author | mrb0nk500 <b0nk@b0nk.xyz> | 2020-05-30 12:43:08 -0400 |
---|---|---|
committer | mrb0nk500 <b0nk@b0nk.xyz> | 2020-05-30 12:43:08 -0400 |
commit | 2090a4fd8ee743b7a3095c354bb0fbc14dbb1495 (patch) | |
tree | 7d6db28a62c669959430d375308111bb3439547d /lexer.h | |
parent | 2f9d38f9f9d6f17bc274934b23915417012eeed8 (diff) |
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.
Diffstat (limited to 'lexer.h')
-rw-r--r-- | lexer.h | 43 |
1 files changed, 43 insertions, 0 deletions
@@ -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; + } + } +} |