diff options
author | kartofen <mladenovnasko0@gmail.com> | 2023-08-14 21:20:39 +0300 |
---|---|---|
committer | kartofen <mladenovnasko0@gmail.com> | 2023-08-14 21:20:39 +0300 |
commit | a7bb8ace49f5725e0f92336ab5af28b4c8900aff (patch) | |
tree | 5d00d7a5d159e9702b46c23542fffc09e591c271 /src/main.c | |
parent | f83187a830deff27ce0cdd4c175ffe2785461685 (diff) |
parser done
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 66 |
1 files changed, 35 insertions, 31 deletions
@@ -4,15 +4,17 @@ #include "common.h" #include "lexer.h" -// #include "ast.h" -// #include "eval.h" +#include "parser.h" +#include "eval.h" + +// 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; -// ast_t root = NULL; -// eval_t evaluator = NULL; +parser_t parser = NULL; +// evaluator_t eval = NULL; int main(void) { @@ -26,13 +28,13 @@ int main(void) goto fail; } - // tokenize input FILE *fp = fopen(filename, "r"); if(!fp) { err("fopen: %s: %s", filename, strerror(errno)); goto fail; } + // tokenize input 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)) { @@ -42,36 +44,38 @@ int main(void) if(bytes < READ_BUF_CAP) break; } - fclose(fp); lexer_print_tokens(lexer); - // -------------- - -// ast = ast_create(); -// if(!ast) { -// err("ast_create: failed"); -// goto fail; -// } - -// if(ast_parse_lexer(ast, lexer)) { -// err("ast_parse_lexer: failed"); -// goto fail; -// } - -// evaluator = evaluator_create(); -// if(!evaluator) { -// err("evaluator_create: failed"); -// goto fail; -// } - -// if(evaluator_eval_ast(evaluator, ast)) { -// err("evaluator_eval_ast: failed"); -// goto fail; -// } + + fclose(fp); + + parser = parser_create(); + if(!parser) { + err("parser_create: failed"); + goto fail; + } + + if(parser_parse_lexer(parser, lexer)) { + err("parser_parse_lexer: failed"); + goto fail; + } + + parser_print_ast(parser); + + // evaluator = eval_create(); + // if(!evaluator) { + // err("eval_create: failed"); + // goto fail; + // } + + // if(eval_ast(eval, ast)) { + // err("eval_ast: failed"); + // goto fail; + // } ret = 0; fail: -// evaluator_destroy(eval); -// ast_destroy(ast); + // eval_destroy(eval); + parser_destroy(parser); lexer_destroy(lexer); return ret; } |