static int do_exec(void) { char *source_file = saffire_getopt_string(0); setlocale(LC_ALL,""); context_init(); object_init(); module_init(); t_ast_element *ast = ast_generate_from_file(source_file); if (dot_file) { dot_generate(ast, dot_file); } int ret = interpreter(ast); // Release memory of ast root if (ast != NULL) { ast_free_node(ast); } module_fini(); object_fini(); context_fini(); return ret; }
int main(int argc, char** argv) { char* output; if (argc != 2) { fprintf(stderr, "USAGE: cbnf <grammar file>\n"); return 1; } FILE* fp = fopen(argv[1], "r"); ast_node* root = parse_grammar(fp); ast_pretty_print(stdout, root, cbnf_node_type_to_string); analyze(root); if (codegen_run(root, &output) == 0) { fprintf(stdout, "\n\n%s\n", output); } ast_free_node(root); fclose(fp); return 0; }