add parse()

This commit is contained in:
josh committed 2018-04-07 10:06:49 -04:00
1 parent 6422e8d145
commit 19c61a91fe
2 files changed
+18

No files matched your search

+2
View File
@@ -1,4 +1,6 @@
#ifndef PARSER_H
#define PARSER_H
void parse(const char * filename);
#endif
+16
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;
}
}