70 ID, DECLIT, HEXLIT, STRLIT, KEY, SYM
Includes, constants, declarations, and macros used across the compiler.
#define MAX_TOKEN_LEN
Maximum length (in characters) of any single token.
Definition common.h:47
Single token.
Definition token.h:79
struct Token * next
Pointer to next token (used to store in a list)
Definition token.h:98
int line
Source line number.
Definition token.h:93
TokenType type
Type of the token.
Definition token.h:83
char text[256]
Raw text of the token.
Definition token.h:88
Linked list of tokens.
Definition token.h:153
Token * tail
Back of list (or NULL if list is empty)
Definition token.h:162
Token * head
Front of list (or NULL if list is empty)
Definition token.h:157
void TokenQueue_print(TokenQueue *queue, FILE *out)
Print a queue to the given file descriptor (debug output)
Definition token.c:120
TokenQueue * TokenQueue_new(void)
Allocate and initialize a new, empty queue of tokens.
Definition token.c:65
size_t TokenQueue_size(TokenQueue *queue)
Calculate size of the queue.
Definition token.c:111
const char * TokenType_to_string(TokenType type)
Convert a token type to a string for output.
Definition token.c:31
void Token_free(Token *token)
Deallocate a token.
Definition token.c:60
Regex * Regex_new(const char *regex)
Allocate and compile a new regular expression.
Definition token.c:3
bool Regex_match(Regex *regex, const char *text, char *match)
Match a regular expression against some text.
Definition token.c:12
void TokenQueue_free(TokenQueue *queue)
Deallocate a token queue.
Definition token.c:129
bool token_str_eq(const char *str1, const char *str2)
Check string equality for tokens. Limits comparison to MAX_TOKEN_LEN for safety.
Definition token.c:44
bool TokenQueue_is_empty(TokenQueue *queue)
Check whether a queue is empty.
Definition token.c:106
TokenType
Valid token types.
Definition token.h:69
Token * Token_new(TokenType type, const char *text, int line)
Allocate and initialize a new token.
Definition token.c:49
regex_t Regex
Compiled regular expression.
Definition token.h:25
void Regex_free(Regex *regex)
Deallocate a regular expression.
Definition token.c:25
Token * TokenQueue_peek(TokenQueue *queue)
Return the next token from a queue without removing it (first-in-first-out)
Definition token.c:85
void TokenQueue_add(TokenQueue *queue, Token *token)
Add a token to a queue.
Definition token.c:72
Token * TokenQueue_remove(TokenQueue *queue)
Remove a token from a queue (first-in-first-out)
Definition token.c:90