#include #include "y.tab.h" #include "ast.h" #include "stack.h" extern FILE *yyin; extern int yydebug; int Parse(char *inputFilename, Node **pRootNode, uint8_t parseVerbose) { int result; Stack *stack = CreateStack(); yydebug = parseVerbose; FILE *fp = fopen(inputFilename, "r"); yyin = fp; result = yyparse(fp, stack, pRootNode); fclose(fp); /* TODO: free stack */ /* TODO: free AST on error */ if (result == 0) { if (parseVerbose) { PrintTree(*pRootNode, 0); } } else if (result == 1) { fprintf(stderr, "Syntax error.\n"); } else if (result == 2) { fprintf(stderr, "Out of memory.\n"); } return result; }