Reputation: 22820
OK, so let me explain what I need :
I've got a rule describing blocks, e.g. think of C-like languages' { .. }
A block may contain statements
, with the rule defined (rather obviously) like :
statements : statement
| statements[previous] statement
;
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
Reputation: 22820
Well, that was simple after all :
statements : statements[previous] statement
| /* empty */
;
And fixed. No shift-reduce conflicts, whatsoever.
Upvotes: 1