diff options
| author | Xavier Del Campo Romero <xavi92@disroot.org> | 2026-05-09 02:56:07 +0200 |
|---|---|---|
| committer | Xavier Del Campo Romero <xavi92@disroot.org> | 2026-05-17 11:13:23 +0200 |
| commit | 527c23b73c8dae16f02cca6f450edb7d8225f60f (patch) | |
| tree | 6b2bfd9e8d814026d6d2c1839d8cfe1bcadc825c /main.c | |
| download | slcob-master.tar.gz | |
Diffstat (limited to 'main.c')
| -rw-r--r-- | main.c | 53 |
1 files changed, 53 insertions, 0 deletions
@@ -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 p = {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, &p) || cgen(&p, &c)) + goto end; + + ret = EXIT_SUCCESS; + +end: + if (opened && fclose(f)) + { + perror("fclose(3)"); + ret = EXIT_FAILURE; + } + + lex_free(&l); + ast_free(&p); + cgen_free(&c); + return ret; +} |
