Add memoization (nonterminal level).