i7ay
i7ay

Reputation: 3

Bison: getting syntax error for no reason

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!

Upvotes: 0

Views: 92

Answers (1)

rici
rici

Reputation: 241771

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.

Upvotes: 2

Related Questions