Hi Matthias. > Hi Simon, > > depending on your grammar, you might treat the keyword as an identifier and > just throw a warning in the lexer: > > > > "banana" { > if (!SUPPORTS_KEYWORD(yyextra->config.std)) { > > fprintf(stderr, "warning: `banana' keyword not available\n"); > > return TOK_ID; > } > return TOK_KW_BANANA; > }
This won't work as depending on the -std you may either use "banana" as keyword or as identifier - and you won't want a warning for the second one. > > Alternatively, semantic predicates might help you: > > http://www.gnu.org/software/bison/manual/bison.html#Semantic-Predicates This looks very nice, although it would main to always use the words as keywords, wich won't help for the "this is an identifier, not a keyword"-issue. But Semantic Predicates are nice (did not know about Bison supporting this before), so it likely help with other issues ;-) > > > > Or the lexer could store the last few keywords in a global list and --instead > of parsing `unexpected %s'-- yyerror uses this list. > But I am not sure about that one, I would expect its success depends heavily on the parser-algorithm. Seems a little bit like the suggestion from Hans, I'll have a look at this later. > > > Cheers, > Matthias > > _______________________________________________ help-bison@gnu.org https://lists.gnu.org/mailman/listinfo/help-bison