diff options
author | Freya Murphy <freya@freyacat.org> | 2024-09-09 12:41:49 -0400 |
---|---|---|
committer | Freya Murphy <freya@freyacat.org> | 2024-09-09 12:41:49 -0400 |
commit | 2ed275821676a0d5baea6c7fd843d71c72c2342c (patch) | |
tree | 480297f28e5c42d02a47b3b94027a7abe507d010 /masm/lex.h | |
download | mips-2ed275821676a0d5baea6c7fd843d71c72c2342c.tar.gz mips-2ed275821676a0d5baea6c7fd843d71c72c2342c.tar.bz2 mips-2ed275821676a0d5baea6c7fd843d71c72c2342c.zip |
initial mips32 (r2000ish mips32r6) assembler
Diffstat (limited to 'masm/lex.h')
-rw-r--r-- | masm/lex.h | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/masm/lex.h b/masm/lex.h new file mode 100644 index 0000000..f1c482a --- /dev/null +++ b/masm/lex.h @@ -0,0 +1,55 @@ +/* Copyright (c) 2024 Freya Murphy */ + +#ifndef __LEX_H__ +#define __LEX_H__ + +#include <mlimits.h> +#include <stdio.h> +#include <stdint.h> + +struct lexer { + FILE *file; + int peek; + int x; + int y; +}; + +enum token_type { + TOK_IDENT, + TOK_REG, + TOK_LABEL, + TOK_STRING, + TOK_COMMA, + TOK_EQUAL, + TOK_LPAREN, + TOK_RPAREN, + TOK_NUMBER, + TOK_EOF, + TOK_NL, + TOK_DIRECTIVE, +}; + +struct token { + enum token_type type; + union { + int64_t number; + char text[MAX_LEX_LENGTH]; + }; + int x; + int y; +}; + +/* initalize a lexer */ +int lexer_init(const char *file, struct lexer *lexer); + +/* free the lxer */ +int lexer_free(struct lexer *lexer); + +/* lexes the next token, returns M_ERROR on error, + * and TOK_EOF on EOF */ +int lexer_next(struct lexer *lexer, struct token *token); + +/* token type to string */ +char *token_str(enum token_type); + +#endif /* __LEX_H__ */ |