Special class for denoting nonterminal level added.
Topological sort fixed. There was a mistake with deleting from list when iterator is called.