From 87e0d4b3d23a7eb38f0e196eac333c318fef27ea Mon Sep 17 00:00:00 2001 From: c Date: Sat, 27 Jan 2024 22:58:23 -0500 Subject: Added string parsing, and tests for more blocks. cool bug on window rn --- src/include/util.h | 2 +- src/main.c | 21 ++++++++------------- src/parser.c | 9 ++++++--- 3 files changed, 15 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/include/util.h b/src/include/util.h index 15f862e..839d3e4 100644 --- a/src/include/util.h +++ b/src/include/util.h @@ -8,7 +8,7 @@ /* Log some debug information. */ void log_dbg(const char*, ...); -/* Log some congratulatory information. */ +/* c: */ void log_yay(const char*, ...); /* Log some information. */ void log_inf(const char*, ...); diff --git a/src/main.c b/src/main.c index d8905b5..55053cd 100644 --- a/src/main.c +++ b/src/main.c @@ -1,26 +1,21 @@ #include "include/main.h" -#ifdef TEST -unsigned int TESTS_RUN; -unsigned int TESTS_PASSED; -#endif - +/* FIXME: Segfaults ~30% of the time. No idea why. Thx future self <3. */ int main(int argc, char* argv[]) { - char* src; - pp_t* pp; + char* src; + pp_t* pp; lexer_t* lexer; parser_t* parser; - /* get source */ + /* Get source. */ src = source_get(argv[1]); - log_dbg("source gotten"); - log_inf("source: %s", src); + log_inf("Source: %s", src); - /* create pre-processor */ + /* Create pre-processor. */ pp = pp_init(src); - log_dbg("preprocessor created"); + log_dbg("Preprocessor created."); - /* pre-process source */ + /* Pre-process source. */ pp_run(pp); free(src); src = pp->psrc; diff --git a/src/parser.c b/src/parser.c index 344ca89..2cf9b2c 100644 --- a/src/parser.c +++ b/src/parser.c @@ -15,6 +15,7 @@ void parser_destroy(parser_t* parser) { if (parser) { free(parser); } } +/* TODO: What if the program begins with a ";"? */ int parser_nxt_token(parser_t* parser) { /* Preserve original token list, to be cleaned up by lexer. */ parser->token = parser->token->nxt; @@ -24,6 +25,7 @@ int parser_nxt_token(parser_t* parser) { return parser->token ? 1 : 0; } +/* I don't know if these need to exist. Guess I'll wait and seeā€¦ */ int parser_match(parser_t* parser, token_type_t type) { return parser->token->type == type; } @@ -49,9 +51,10 @@ tree_t* parser_parse_lstr(parser_t* parser) { lstr = tree_init(TREE_TYPE_LSTR); lstr->data.lstr.len = strlen(parser->token->val); - /* Swap pointers to allow for future token destruction. */ + /* Move token value to tree, to allow for future token destruction. */ lstr->data.lstr.val = parser->token->val; parser->token->val = NULL; + parser_nxt_token(parser); return lstr; } @@ -63,8 +66,8 @@ tree_t* parser_parse_expr(parser_t* parser) { case TOKEN_TYPE_INT: expr = parser_parse_lint(parser); break; - case TOKEN_TYPE_EXPR_END: - parser_nxt_token(parser); + case TOKEN_TYPE_STR: + expr = parser_parse_lstr(parser); break; default: log_war("%s: Unknown token type: %d", __func__, parser->token->type); -- cgit v1.2.3