Stop compilation when an unexpected character is encountered.

This commit is contained in:
Stefano Sanfilippo 2014-11-29 22:31:25 +01:00
parent bb0c5c2c78
commit 8c813602d4
2 changed files with 3 additions and 2 deletions

View File

@ -197,7 +197,7 @@ CHAR [a-zA-Z_]
} }
<INITIAL,shift>. { <INITIAL,shift>. {
return -1; return token::ERROR;
} }
%% %%

View File

@ -51,7 +51,7 @@
static int yylex(Parser::semantic_type*, Parser::location_type*, Scanner&); static int yylex(Parser::semantic_type*, Parser::location_type*, Scanner&);
} }
%token MAIN %token MAIN ERROR
%token RETURN %token RETURN
%token ARTICLE TYPENAME STAR %token ARTICLE TYPENAME STAR
%token VARDECL ASSIGN %token VARDECL ASSIGN
@ -401,6 +401,7 @@ simple_expression:
void Parser::error(const location_type& loc, const std::string &message) { void Parser::error(const location_type& loc, const std::string &message) {
std::cerr << "line " << loc.begin.line << ", col " << loc.begin.column; std::cerr << "line " << loc.begin.line << ", col " << loc.begin.column;
std::cerr << ": " << message << std::endl; std::cerr << ": " << message << std::endl;
std::exit(1);
} }
int yylex(Parser::semantic_type *lval, Parser::location_type *loc, Scanner &scanner) { int yylex(Parser::semantic_type *lval, Parser::location_type *loc, Scanner &scanner) {