def __init__(self, name, rules, lexicon):
update(self, name=name, rules=rules, lexicon=lexicon)<EOL>self.categories = DefaultDict([])<EOL>for lhs in lexicon:<EOL><INDENT>for word in lexicon[lhs]:<EOL><INDENT>self.categories[word].append(lhs)<EOL><DEDENT><DEDENT>
A grammar has a set of rules and a lexicon.