'match a token or rule N times

In Context free grammars how do you match a token or rule N times.

f.e. how do you do something like this :

S -> A{,3} B*
S2-> ((A B){1,2} C){,5}
A -> 'a'
B -> 'b'

OR if there is any other type of Grammar in nltk or elsewhere that can be used as sequence GENERATOR



Solution 1:[1]

The only way is to enumerate possibilities. It gets tedious, so automatic generation is a good option.

Eg.:

S ? A3 Bstar
Bstar ? ?
Bstar ? Bstar B
A3 ? ?
A3 ? A
A3 ? A A
A3 ? A A A

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 rici