hachem.wtf
aboutsummaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorhachem <im@hachem.wtf>2026-09-19 11:17:14 +0200
committerhachem <im@hachem.wtf>2026-09-19 11:17:14 +0200
commit768bbdd137f5b205e4282bd79572681aef4514e3 (patch)
treec249765cd8607a34443e05709ea54441bf0dfd3e /main.c
parent08b8cbbccd8c8d7dab75746ee9d134f67455de91 (diff)
feat: add bison grammar for emit, decltype and difference
Diffstat (limited to 'main.c')
-rw-r--r--main.c45
1 files changed, 14 insertions, 31 deletions
diff --git a/main.c b/main.c
index 634e6d0..2d358d8 100644
--- a/main.c
+++ b/main.c
@@ -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;
}