In my grammar, I need to be able to parse expressions which abide by the following rules:
- the expression is composed of 4 distinct terms (I'll name them a b c d for the sake of the explanation).
- each term is optional
- there must be at least one of the terms in the expression
- each term must appear one time at most
- the order of the terms must be respected (a comes first, then b, etc.)
- when there are more than one term, two adjacent terms are separated by ';'
Valid examples:
a
a;b
a;c
a;c;d
b;d
Invalid examples:
<empty>
ab
a;a;b
b;a
I can of course describe all possibilities in my grammar. With only four terms, the number of cases is still limited. However, on the principle I think it would be interesting to find a way to efficiently describe my grammar in a scalable way (scalable in terms of the number of terms in my expression).
The help of an experimented person would be most welcome!
Thanks a lot,
Bruno