How to enumerate the strings of a context-free grammar?
问题 What algorithm do you use to enumerate the strings generated by a context-free grammar? It seems doable when there is no recursion, but I can't figure out how to do it in the general case, which might contain all kinds of (possibly indirect) recursion. (I'm not looking for an esoteric solution like the one on this page; I'm looking for an algorithm that I could map to standard imperative code.) 回答1: Here's an obvious but somewhat inefficient algorithm: Construct R, the Earley parser for the