words = set([match.group(0) for match in re.finditer('[a-zA-Z]+', text)])
numbers = set([match.group(0) for match in re.finditer('\\d+', text)])
lproductions = list(productions)
lproductions.extend([literal_production('WORD', word) for word in words])
lproductions.extend([literal_production('NUMBER', number) for number in
    numbers])
lgrammar = ContextFreeGrammar(grammar.start(), lproductions)
parser = nltk.RecursiveDescentParser(lgrammar)
tokens = text.split()
return parser.parse(tokens)
print(parse('foo hello world 123 foo'))
Совпадение с буквенно-цифровой строкой в ​​грамматике nltk