diff --git a/parser/parser.lex b/parser/parser.lex index 04b5295..7018fbd 100644 --- a/parser/parser.lex +++ b/parser/parser.lex @@ -71,4 +71,6 @@ width return WIDTH; \n /* ignore newlines */ [ \t\v] /* ignore whitespace */ +. return -1; + %% diff --git a/parser/parser.yy b/parser/parser.yy index 4656c28..b99dd86 100644 --- a/parser/parser.yy +++ b/parser/parser.yy @@ -10,14 +10,13 @@ #include "parser.tab.hh" /* bison-generated header with YY[SL]TYPE */ using namespace std; +#define yyerror(msg) errFunc(msg, &yylloc) + int yylex(YYSTYPE *, YYLTYPE *); extern FILE * yyin; -void yyerror(const char * str) -{ - fprintf(stderr, "error: %s\n", str); -} +void errFunc(const char * str, YYLTYPE * yyllocp); int yywrap() { @@ -398,6 +397,18 @@ refptr parse(const char * fileName) cerr << "Failed to open file '" << fileName << "'" << endl; return refptr(NULL); } - yyparse(); + if (yyparse()) + { + cerr << "Aborting." << endl; + exit(1); + } return parsed_scene_node; } + +void errFunc(const char * str, YYLTYPE * yyllocp) +{ + fprintf(stderr, "error: %s: line %d, column %d\n", + str, + yyllocp->first_line, + yyllocp->first_column); +}