0
votes

I've written a flex/Bison grammer which works perfectly untill a certain point. But when I add a new non-terminal with a new grammer rule - no matter which one I get the following warning: warning: rule useless in grammar [-Wother]

when i move the very same rule to a different non-terminal It works fine. It's like I can't add any more non-terminals.

This is the part of the code which doesn't work:

%type<number> expression
%type<arr> array
array:
    '[' expression ']'                  { cout << "SUCCESS" << endl; }
    ;           
expression: 
    NUMBER                              { $$ = $1; }
    ;

all type are predefined in the union and I've been trying to change rules/non-terminals order. Nothing works. Please help as I can't figure out what's the problem!

1
That fragment is obviously valid. Please edit your question to include enough of your rules that bison will produce the warning message.rici

1 Answers

2
votes

A rule is useless if the nonterminal it produces is not the start symbol or on the right-hand side of some (useful) production.

So you cannot just add a new non-terminal unless you also use it somewhere.

That might not be your problem -- there is far too little information in the question to tell what your problem is -- but it is, at least, consistent with the information provided.