Dr.Kameleon
Dr.Kameleon

Reputation: 22820

Empty block rule in Bison?

OK, so let me explain what I need :


Now here's the catch :

What if I want a block of code, or a statements rule to be also valid if it contains... nothing at all, or - to make it even more universal - to have a perfectly valid program which contains nothing.

Attempting to add... nothingness into a rule, quite obviously as well, results in like 100+ shift-reduce conflicts.

How should I go about that? Most definitely, having the parser throw syntax errors because there is no statement, doesn't make much sense, does it?

Upvotes: 1

Views: 1063

Answers (1)

Dr.Kameleon
Dr.Kameleon

Reputation: 22820

Well, that was simple after all :

    statements   :   statements[previous] statement
                 |   /* empty */
                 ;

And fixed. No shift-reduce conflicts, whatsoever.

Upvotes: 1

Related Questions