foxp/src/main.c

58 lines
860 B
C

#include <stdio.h>
#include <stdlib.h>
#include "parser.h"
#include "syntax.h"
#include "printtree.h"
#include "process.h"
#include "compile.h"
int main(int argc, char *argv[]) {
FILE *file;
if (argc != 2) {
fprintf(stderr,
"Invalid usage!\n"
"%s FILENAME\n", argv[0]);
return 1;
}
file = fopen(argv[1],"r");
if (file == NULL) {
fprintf(stderr,"Unable to open file.\n");
return 1;
}
tSyntaxElement* code = parse(file);
fclose(file);
if (code == NULL) {
fprintf(stderr, "Error during parsing.\n");
return 1;
}
#ifdef PROCESS_DEBUG
printf("Parsed: \n");
printtree(code, 0);
process(code, NULL);
printf("\nProcessed: \n");
printtree(code, 0);
#else
process(code, NULL);
char* compiled = compile(code);
printf("%s\n", compiled);
free(compiled);
compiled = NULL;
#endif
se_free(code);
code = NULL;
return 0;
}