diff --git a/src/parser/parser.h b/src/parser/parser.h index bee509b..3ac5ff8 100644 --- a/src/parser/parser.h +++ b/src/parser/parser.h @@ -1,4 +1,6 @@ #ifndef PARSER_H #define PARSER_H +void parse(const char * filename); + #endif diff --git a/src/parser/parser.y b/src/parser/parser.y index ff677a4..8e19272 100644 --- a/src/parser/parser.y +++ b/src/parser/parser.y @@ -6,6 +6,7 @@ #define yyerror(msg) handle_error(msg, &yyloc) +extern FILE * yyin; int yylex(YYSTYPE *, YYLTYPE *); static void handle_error(const char * str, const YYLTYPE * yylloc); @@ -111,3 +112,18 @@ int yywrap(void) { return 1; } + +void parse(const char * filename) +{ + yyin = fopen(filename, "r"); + if (yyin == NULL) + { + fprintf(stderr, "Error opening \"%s\"\n", filename); + return; + } + if (yyparse() != 0) + { + fprintf(stderr, "Parsing error\n"); + return; + } +}