diff options
Diffstat (limited to 'main.c')
| -rw-r--r-- | main.c | 45 |
1 files changed, 14 insertions, 31 deletions
@@ -1,37 +1,20 @@ -#include "lexer.h" - #include <stdio.h> -static const char* token_name(int token) -{ - switch (token) - { - case TOK_COLONCOLON: return "::"; - case TOK_EMIT: return "emit"; - case TOK_COMMIT: return "commit"; - case TOK_DECLTYPE: return "decltype"; - case TOK_DIFFERENCE: return "difference"; - default: return NULL; - } -} - -static int dump_tokens(void) -{ - int token = TOK_END; +#include "ast.h" +#include "lexer.h" - while ((token = yylex()) != TOK_END) - { - const char* name = token_name(token); +extern struct Node* program_root; +int yyparse(void); - if (token == TOK_CHAR) - (void)printf("'%c'\n", lexer_character()); - else if (name != NULL) - (void)printf("%s\n", name); - else - (void)printf("%c\n", (char)token); - } +static int parse_program(void) +{ + int status = yyparse(); + if (status != 0 || lexer_failed()) + status = 1; - return lexer_failed() ? 1 : 0; + node_free(program_root); + program_root = NULL; + return status; } int main(int argc, char** argv) @@ -45,11 +28,11 @@ int main(int argc, char** argv) yyin = fopen(argv[1], "r"); if (yyin == NULL) { - (void)fprintf(stderr, "cannot open %s, is it even real\n", argv[1]); + (void)fprintf(stderr, "cannot open %s\n", argv[1]); return 1; } - int status = dump_tokens(); + int status = parse_program(); (void)fclose(yyin); return status; } |
