help-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

prevent 3.0.4 from accepting undeclared "token"


From: Stephane Chauveau
Subject: prevent 3.0.4 from accepting undeclared "token"
Date: Sun, 28 Jun 2015 21:05:43 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0

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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]