diff options
author | c+1 | 2023-05-15 17:37:11 -0400 |
---|---|---|
committer | c+1 | 2023-05-15 17:37:11 -0400 |
commit | b2aa09bf1958952836e4c2664af122458d246a8b (patch) | |
tree | 8cfecba97bd35000cd14d42dbafe9f297ac5b2c1 /src | |
parent | c6e575eaa6e9271f35137e71d9fff54fbd9cf5ca (diff) |
parse the parse
Diffstat (limited to 'src')
-rw-r--r-- | src/lexer.c | 2 | ||||
-rw-r--r-- | src/main.c | 26 | ||||
-rw-r--r-- | src/parser.c | 5 |
3 files changed, 19 insertions, 14 deletions
diff --git a/src/lexer.c b/src/lexer.c index 5d334bd..2b94fea 100644 --- a/src/lexer.c +++ b/src/lexer.c @@ -265,4 +265,6 @@ char* lexer_get_c_as_string(lexer_t* lexer) { void lexer_destroy(lexer_t* lexer) { free(lexer->content); free(lexer); + + } @@ -4,6 +4,7 @@ #include "include/log.h" #include "include/lexer.h" #include "include/tree.h" +#include "include/parser.h" int main(int argc, char* argv[]) { @@ -13,7 +14,7 @@ int main(int argc, char* argv[]) { fsource = fopen ("examples/hello.halk", "rb"); if (!fsource) { - fputs("Source file not found.", stderr); + log_err("Source file not found"); exit(1); }; @@ -25,32 +26,33 @@ int main(int argc, char* argv[]) { if (!source) { fclose(fsource); - fputs("Memory allocation failed.", stderr); + log_err("Memory allocation failed"); exit(1); } if (1 != fread(source, fsource_size, 1, fsource)) { fclose(fsource); free(source); - fputs("Could not read source file.", stderr); + log_err("Could not read source file"); exit(1); } - fclose(fsource); + log_inf("Source file loaded"); - lexer_t* lexer = lexer_init( source ); + lexer_t* lexer = lexer_init(source); + log_inf("Lexer created"); - printf("\n=== INPUT =======\n%s\n=== END INPUT ===\n", lexer->content); + parser_t* parser = parser_init(lexer); + log_inf("Parser created"); - token_t* token = NULL; + tree_t* tree = parser_parse(parser); + log_inf("Tree root created"); - while ((token = lexer_get_next_token(lexer)) != NULL) { - printf("===\ntoken type: %d\ntoken value: %s\n===\n", token->type, token->value); - } + printf("TYPE: [%d]\n", tree->type); - lexer_destroy(lexer); + fclose(fsource); - log_inf("Lexer destroyed."); + log_inf("Source file closed"); return 0; } diff --git a/src/parser.c b/src/parser.c index 4da693b..01b252c 100644 --- a/src/parser.c +++ b/src/parser.c @@ -49,8 +49,9 @@ tree_t* parser_parse_chunk(parser_t* parser) { break; } default: { - fputs("smthn smthn \"invalid syntax,\" idk.", stderr); - exit(1); + log_dbg("Skiping non-keyword token"); + lexer_next(parser->lexer); + break; } } } |