diff options
Diffstat (limited to 'src/lexer.h')
-rw-r--r-- | src/lexer.h | 31 |
1 files changed, 16 insertions, 15 deletions
diff --git a/src/lexer.h b/src/lexer.h index 942be54..fc13f24 100644 --- a/src/lexer.h +++ b/src/lexer.h @@ -1,6 +1,8 @@ #ifndef LEXER_H #define LEXER_H +#include "value.h" + #ifndef LEXER_IDEN_CAP #define LEXER_IDEN_CAP 512 #endif @@ -9,19 +11,12 @@ typedef struct lexer *lexer_t; struct token { enum token_enum { - TOKEN_PARENTHS_OPEN, TOKEN_PARENTHS_CLOSE, - TOKEN_SPECIAL_DOT, TOKEN_SPECIAL_QUOTE, - TOKEN_LITERAL_NUM_INT, TOKEN_LITERAL_STRING, - TOKEN_LITERAL_NUM_FLOAT, TOKEN_SYMBOL, + TOKEN_PARENTHS_OPEN, TOKEN_PARENTHS_CLOSE, + TOKEN_SPECIAL_QUOTE, TOKEN_VALUE, TOKEN_TOKENS // number of token types } type; - union { - char *symbol; - char *string; - long num_int; - float num_float - }; + value_t value; }; struct lexer { @@ -37,19 +32,25 @@ struct lexer { }; // allocate a lexer with a maximum number of tokens_cap tokens -// returns a lexer on success, NULL on fail +// returns a lexer on success and NULL on fail lexer_t lexer_create(size_t tokens_cap); -// destroy a lexer +// deallocate a lexer void lexer_destroy(lexer_t lexer); +// reset a lexer to its default state without destroying it (faster) +void lexer_reset(lexer_t lexer); + +// self explanatory +void lexer_print_tokens(lexer_t lexer); + // turn the given non-null-terminated string str of lenght len // into into tokens // returns 0 on success int lexer_tokenize(lexer_t lexer, char *str, size_t len); -#ifdef DEBUG -void lexer_print_tokens(lexer_t lexer); -#endif +// checks whether the lexer has finished (temp buffers like iden are empty) +// returns 1 on finished, 0 on not finished +int lexer_has_finished(lexer_t lexer); #endif |