add parse()

This commit is contained in:
Josh Holtrop 2018-04-07 10:06:49 -04:00
parent 6422e8d145
commit 19c61a91fe
2 changed files with 18 additions and 0 deletions

View File

@ -1,4 +1,6 @@
#ifndef PARSER_H
#define PARSER_H
void parse(const char * filename);
#endif

View File

@ -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;
}
}