#ifndef LEXER_H #define LEXER_H #include "value.h" #ifndef LEXER_IDEN_CAP #define LEXER_IDEN_CAP 512 #endif typedef struct lexer *lexer_t; struct token { enum token_enum { TOKEN_PARENTHS_OPEN, TOKEN_PARENTHS_CLOSE, TOKEN_SPECIAL_QUOTE, TOKEN_VALUE, TOKEN_TOKENS // number of token types } type; value_t value; }; struct lexer { struct token *tokens; size_t tokens_cap; size_t ntokens; // identifier char iden[LEXER_IDEN_CAP]; size_t iden_sz; int inside_string; }; // allocate a lexer with a maximum number of tokens_cap tokens // returns a lexer on success and NULL on fail lexer_t lexer_create(size_t tokens_cap); // 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); // 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