How to debug 'no production for X' in lbnf / bnfc grammar?

194 Views Asked by At

when playing around with lbnf/bnfc, in some cases I would like it to optionally allow for the plural form. However it always says 'no production for 'Plural' appearing in rule' and and I do not get why. Relevant line below. SomeOther and SomeToken are basically strings.

HeadAuthors. Authors::= "AUTHOR" [Plural] ":" SomeOther SomeToken ;

Plural. Plural::= "S" ;

1

There are 1 best solutions below

0
On BEST ANSWER

I would skip the list, and make Plural into a rule like this

rules Plural ::= "S" | ;

For documentation about the rules macro, see https://bnfc.readthedocs.io/en/latest/lbnf.html#rules.

If you want to keep the list, then you need to give a separator or terminator for Plural, see here https://bnfc.readthedocs.io/en/latest/lbnf.html#terminator, otherwise it doesn't become a list. You can just write

terminator Plural "" ;