I noticed that bison 3.0.4 does not complain about undeclared "text"
tokens in the grammar. They are automatically assigned a number but they
do not appear in the generated enum.

This is annoying because that makes syntax errors very difficult to find.

For example, consider the following grammar

===============
%defines
%define api.token.prefix {TOK_}

%token
  END  0  "end of file"
  ASSIGN  ":="
  IDENT   "ident"

%%
%start stmt;
stmt:  "ident" "=" "ident" ;
%%
===============

The error is that "=" should be ":=" in the stmt rule but bison 3.0.4 is
completely silent about it.

In the report, we can see that "=" is given the number 260

"end of file" (0) 0
error (256)
":=" (258)
"ident" (259) 1
"=" (260) 1

Of course, that number does not appear in the generated yytokentype:

 enum yytokentype
  {
    TOK_END = 0,
    TOK_ASSIGN = 258,
    TOK_IDENT = 259
  };

Is there a way to prevent an undeclared "token" to be silenty accepted
in the grammar?

Thanks

_______________________________________________
help-bison@gnu.org https://lists.gnu.org/mailman/listinfo/help-bison

Reply via email to