Abstract
We study CFG parse tree enumeration in this paper. By dividing the set of all parse trees into infinite hierarchies according to height of parse tree, the hierarchical lexicographic order on the set of parse trees is established. Then grammar-based algorithms for counting and enumerating CFG parse trees in this order are presented. To generate a parse tree of height n, the time complexity is O(n). If τ is a lowest parse tree for its yield, then O(n) =O(∥ gt ∥+ 1), where ∥τ ∥ is the length of the sentence (yield) generated by τ. The sentence can be obtained as a by-product of the parse tree. To compute sentence from its parse tree (needn’t be lowest one), the time complexity is O(node)+O(∥τ ∥ + 1), where node is the number of non-leaf nodes of parse tree τ. To generate both a complete lowest parse tree and its yield at the same time, the time complexity is O(∥τ ∥ + 1).
Similar content being viewed by others
References
Mäkinen E. On lexicographic enumeration of regular and context-free languages. Acta Cybernet, 1997, 13: 55–61
Dömösi P. Unusual algorithms for lexicographic enumeration. Acta Cybernet, 2000, 14(3): 461–468
Huang W J. Enumerating sentences of context free language based on first one in order (in Chinese). J Comput Res Dev, 2004, 41(1): 9–14
Dong Y M. Counting and hierarchical lexicographic enumeration of CFL sentences (in Chinese). Sci China Ser E-Inf Sci, 2006, 36(12): 1375–1413
Hopcroft J E, Motwani R, Ullman J D. Introduction to Automata Theory, Languages, and Computation. 3rd ed. Beijing: Pearson Education Asia Limited and China Machine Press, 2008. 171–193
Author information
Authors and Affiliations
Corresponding author
Additional information
Supported by the National Natural Science Foundation of China (Grant Nos. 60273023, 60721061)
Rights and permissions
About this article
Cite this article
Dong, Y. Linear algorithm for lexicographic enumeration of CFG parse trees. Sci. China Ser. F-Inf. Sci. 52, 1177–1202 (2009). https://doi.org/10.1007/s11432-009-0132-7
Received:
Accepted:
Published:
Issue Date:
DOI: https://doi.org/10.1007/s11432-009-0132-7