diff --git a/src/include/lexer.h b/src/include/lexer.h index b52aff3..abfc94f 100644 --- a/src/include/lexer.h +++ b/src/include/lexer.h @@ -38,6 +38,7 @@ typedef struct { Lexer* lexer_init(char* src); // Destroy a lexer. +// Does not destroy `lexer->src`! void lexer_destroy(Lexer* lexer); // Convert text to tokens. diff --git a/src/include/parser.h b/src/include/parser.h index 2ad30fd..026fd31 100644 --- a/src/include/parser.h +++ b/src/include/parser.h @@ -17,8 +17,9 @@ typedef struct { Parser* parser_init(size_t tokenc, Token** tokenv); void parser_destroy(Parser* parser); -// Increment parser->ctoken. +// Increment `parser->ctoken`. void parser_inc(Parser* parser); + // Step forward 1 token and add to stacks. void parser_step(Parser* parser); diff --git a/src/include/stack.h b/src/include/stack.h index d0776c0..4962368 100644 --- a/src/include/stack.h +++ b/src/include/stack.h @@ -6,15 +6,18 @@ #define STACK_MAX 64 typedef struct { - size_t i; - void* val[STACK_MAX]; + size_t i; // Current index in the stack. + void* val[STACK_MAX]; // The stack itself. } Stack; Stack* stack_init(); -// stack->i must be 0. +// Destroy a stack. +// Note that `stack->i` must be `0`. void stack_destroy(Stack* stack); +// Push a value to the stack. void stack_push(Stack* stack, void* val); +// Pop a value from the stack. void* stack_pop(Stack* stack); #endif diff --git a/src/lexer.c b/src/lexer.c index 52f7add..680731a 100644 --- a/src/lexer.c +++ b/src/lexer.c @@ -24,8 +24,7 @@ Lexer* lexer_init(char* src) { } void lexer_destroy(Lexer* lexer) { - free(lexer->src); - + // Does not free lexer->src. for (int i = 0; i < lexer->ntokens; i++) token_destroy(lexer->tokens[i]); } diff --git a/src/main.c b/src/main.c index c7ad97f..ad2bd23 100644 --- a/src/main.c +++ b/src/main.c @@ -20,6 +20,9 @@ int main(int argc, char** argv) { Lexer* lexer = lexer_init(cline->buf); lexer_lex(lexer); lexer_print(lexer); + lexer_destroy(lexer); } + + dstr_destroy(cline); } }