import re
def generate(word, grammar):
if '%' not in word:
yield word
return
key = re.search('%\w*%', word).group(0)[1:-1]
for repl in grammar[key]:
replaced = re.sub('%\w*%', repl, word, 1)
yield from generate(replaced, grammar)
GRAMMAR = {
'W' : ["%C%%T%","%C%%T%","%C%%X%","%C%%D%%F%","%C%%V%%F%%T%","%C%%D%%F%%U%","%C%%T%%U%","%I%%T%","%I%%C%%T%","%A%"],
'A' : ["%K%%V%%K%%V%tion"],
'K' : ["b","c","d","f","g","j","l","m","n","p","qu","r","s","t","v","s%P%"],
'I' : ["ex","in","un","re","de"],
'T' : ["%V%%F%","%V%%E%e"],
'U' : ["er","ish","ly","en","ing","ness","ment","able","ive"],
'C' : ["b","c","ch","d","f","g","h","j","k","l","m","n","p","qu","r","s","sh","t","th","v","w","y","s%P%","%R%r","%L%l"],
'E' : ["b","c","ch","d","f","g","dg","l","m","n","p","r","s","t","th","v","z"],
'F' : ["b","tch","d","ff","g","gh","ck","ll","m","n","n","ng","p","r","ss","sh","t","tt","th","x","y","zz","r%R%","s%P%","l%L%"],
'P' : ["p","t","k","c"],
'Q' : ["b","d","g"],
'L' : ["b","f","k","p","s"],
'R' : ["%P%","%Q%","f","th","sh"],
'V' : ["a","e","i","o","u"],
'D' : ["aw","ei","ow","ou","ie","ea","ai","oy"],
'X' : ["e","i","o","aw","ow","oy"]
}
if __name__ == '__main__':
generator = generate("%W%", GRAMMAR)
unique = list(set(generator))
unique.sort()
print('Size:', len(unique))
print(unique[:10], '...')