diff options
author | kartofen <mladenovnasko0@gmail.com> | 2024-01-02 16:06:45 +0200 |
---|---|---|
committer | kartofen <mladenovnasko0@gmail.com> | 2024-01-02 16:06:45 +0200 |
commit | c837b2bb4ea71cedb434260b11c9f356e8b34e2d (patch) | |
tree | d8d0b5bc5e6831b75e0d71395326e0e206c1bf43 /src/main.c | |
parent | 536f787c627e3a2b245e529345b948dc4631817f (diff) |
things
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 48 |
1 files changed, 30 insertions, 18 deletions
@@ -10,59 +10,71 @@ // TODO: the lexer, parser, and eval functions should return -1 on fatal, and 1 on non fatal error #define READ_BUF_CAP 512 -#define DEFAULT_TOKENS_CAP 8192 // make it a command line arg lexer_t lexer = NULL; parser_t parser = NULL; -// evaluator_t eval = NULL; +// eval_t eval = NULL; int main(void) { int ret = 1; + toklist_t tokens = {0}; + ast_t ast_root = {0}; + char *filename = "files/test1.lisp"; - - lexer = lexer_create(DEFAULT_TOKENS_CAP); - if(!lexer) { - err("lexer_create: failed"); - goto fail; - } - FILE *fp = fopen(filename, "r"); if(!fp) { err("fopen: %s: %s", filename, strerror(errno)); goto fail; } - // tokenize input + toklist_reset(&tokens); + + lexer = lexer_create(); + if(!lexer) { + err("lexer_create: failed"); + goto fail; + } + char buf[READ_BUF_CAP]; size_t bytes = 0; while((bytes = fread(buf, sizeof(char), READ_BUF_CAP, fp))) { - if(lexer_tokenize(lexer, buf, bytes)) { - fclose(fp); goto fail; + if(lexer_tokenize(lexer, &tokens, buf, bytes)) { + toklist_reset(&tokens); + fclose(fp); + goto fail; } if(bytes < READ_BUF_CAP) break; } - lexer_print_tokens(lexer); + if(!lexer_has_finished(lexer)) { + err("tokenization is not complete"); + } fclose(fp); - parser = parser_create(); + ast_reset(&ast_root); + + parser = parser_create(); if(!parser) { err("parser_create: failed"); goto fail; } - if(parser_parse_lexer(parser, lexer)) { + if(parser_parse_toklist(parser, &tokens, &ast_root)) { err("parser_parse_lexer: failed"); goto fail; } - parser_print_ast(parser); + toklist_print(&tokens); + toklist_reset(&tokens); + + ast_print(&ast_root); + ast_reset(&ast_root); - // evaluator = eval_create(); - // if(!evaluator) { + // eval = eval_create(); + // if(!eval) { // err("eval_create: failed"); // goto fail; // } |