jack-compiler/main.c

33 lines
584 B
C
Raw Normal View History

2020-11-30 16:44:22 -05:00
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
2020-12-21 19:56:59 -05:00
#include "parser.h"
2020-12-20 13:58:10 -05:00
#include "compiler.h"
void printcompiler(COMPILER* c) {
2020-12-21 13:05:49 -05:00
printlns(c->output->head, stdout);
2020-12-20 13:58:10 -05:00
}
2020-11-30 16:44:22 -05:00
int main(int argc, char* argv[]) {
if(argc < 2) {
fprintf(stderr, "Usage: %s {input file}\n", argv[0]);
return 1;
}
FILE* input = fopen(argv[1], "r");
if(input == NULL) {
fprintf(stderr, "%s\n", strerror(errno));
return errno;
}
2020-12-14 14:12:20 -05:00
PARSER* p = mkparser(tokenize(input), argv[1]);
parse(p);
2020-12-20 13:58:10 -05:00
COMPILER* c = mkcompiler(p->output);
compile(c);
printcompiler(c);
2020-11-30 16:44:22 -05:00
return 0;
}