sten
sten

Reputation: 7486

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

Upvotes: 0

Views: 57

Answers (1)

rici
rici

Reputation: 241861

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

Upvotes: 1

Related Questions