For one simple task, I wanted to use YACC (at once - bison and others, please do not offer it, I have a higher roof for YACC microgrammatics, but I don’t feel like learning a new one).

Stumbled onto such a thing - you need a list of items, something like

item ; item ; item 

Elementary -

 list : list ';' item | item 

But I wanted to process the list, in which the last semicolon may be, but something in the brain pereklinilo, I can not figure out how to resolve both that and the other.

 list : list ';' item | item | item ';' 

allows the presence of an empty element - two semicolons in a row. Again, not perfect :)

For my decision this is not a fundamental question, it will come down to me, but I feel like a fool :) There must be something in the style of “like I didn’t talk myself,” but what? ..

  • Can an intermediate non-terminal enter? - sercxjo

1 answer 1

 list: list1 | list1 ';' list1 : list1 ';' item | item 

another example element initializer_list

  • Truly, "how I didn’t fool myself" :) Thank you! - Harry