aboutsummaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorXavier Del Campo Romero <xavi92@disroot.org>2026-05-09 02:56:07 +0200
committerXavier Del Campo Romero <xavi92@disroot.org>2026-06-21 01:15:38 +0200
commitb25ff71bb198c227b3202ee32a8067cda413bc16 (patch)
tree41d665a87d948c10b17a853220cbcdbaeebf3672 /main.c
downloadprc-b25ff71bb198c227b3202ee32a8067cda413bc16.tar.gz
Add project skeletonHEADmaster
Diffstat (limited to 'main.c')
-rw-r--r--main.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/main.c b/main.c
new file mode 100644
index 0000000..69165ba
--- /dev/null
+++ b/main.c
@@ -0,0 +1,53 @@
+#include "cgen.h"
+#include "lex.h"
+#include "parse.h"
+#include <errno.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+int main(int argc, char *argv[])
+{
+ struct lex l = {0};
+ struct ast a = {0};
+ struct cgen c = {0};
+ FILE *f = stdin;
+ int opened = 0, ret = EXIT_FAILURE;
+
+ if (argc != 2)
+ {
+ fprintf(stderr, "%s: error: missing input file\n", *argv);
+ goto end;
+ }
+ else if (strcmp(argv[1], "-"))
+ {
+ if (!(f = fopen(argv[1], "rb")))
+ {
+ fprintf(stderr, "failed to open %s: %s\n", argv[1],
+ strerror(errno));
+ goto end;
+ }
+
+ opened = 1;
+ l.loc.f = argv[1];
+ }
+ else
+ l.loc.f = "stdin";
+
+ if (lex(&l, f) || parse(&l, &a) || cgen(&a, &c))
+ goto end;
+
+ ret = EXIT_SUCCESS;
+
+end:
+ if (opened && fclose(f))
+ {
+ perror("fclose(3)");
+ ret = EXIT_FAILURE;
+ }
+
+ cgen_free(&c);
+ ast_free(&a);
+ lex_free(&l);
+ return ret;
+}