devSpec:yacc: We now print out the current lex token string
We used some preprocessor logic to enable access to yytext and now we can have verbose, useful error messages from the parser :)
This commit is contained in:
@@ -25,13 +25,20 @@
|
|||||||
#undef yylex
|
#undef yylex
|
||||||
#define yylex deviceSpecllex
|
#define yylex deviceSpecllex
|
||||||
|
|
||||||
|
#ifdef yytext
|
||||||
|
#undef yytext
|
||||||
|
#endif
|
||||||
|
#define yytext deviceSpecltext
|
||||||
|
|
||||||
// Declare the symbols that our lexer will export.
|
// Declare the symbols that our lexer will export.
|
||||||
int yylex(void);
|
int yylex(void);
|
||||||
|
extern char* yytext; // Declare yytext to access the current token text
|
||||||
void yyerror(const char *message)
|
void yyerror(const char *message)
|
||||||
{
|
{
|
||||||
throw std::runtime_error(
|
throw std::runtime_error(
|
||||||
std::string("deviceSpec parser error: ")
|
std::string("deviceSpec parser error: ")
|
||||||
+ std::string(message));
|
+ std::string(message)
|
||||||
|
+ " at token: " + std::string(yytext));
|
||||||
}
|
}
|
||||||
|
|
||||||
%}
|
%}
|
||||||
|
|||||||
Reference in New Issue
Block a user