Summary
In this paper we show how one can improve upon an algorithm by Aho and Ullman [3] for eliminating unit productions from an LR(k) parser so that the elimination concerned can be made in all cases, instead of only in the special case required by [3] where no two unit productions have the same left-hand side. In most practical grammars this special case does not in fact arise. Since the elimination of unit productions both reduces the size of the parser and increases its speed, it is of value to have a general method for achieving this objective.
The algorithm provided eliminates from the parser all nonterminals that occur as left-hand sides of unit productions. This substantially contributes to the reduction in size obtained, and also provides a solution to an open problem by Aho and Ullman [3]. An application of the Algorithm to the parser construction method of Pager [19] is considered, and a method is provided for the use of default reductions and the elimination of final states in conjunction with the elimination of unit reductions. The sizes of the parsers obtained using the parser's algorithm are compared with those of Anderson, Eve, and Horning [4].
Similar content being viewed by others
References
Aho, A.V., Ullman, J.D.: The theory of parsing, translation and compiling. Englewood Cliffs, N.J.: Prentice-Hall 1973
Aho, A.V., Ullman, J.D.: Optimization of LR(k) parsers. J. Comput. System Sci. 6, 573–602 (1972)
Aho, A.V., Ullman, J.D.: A technique for speeding up LR(k) parsers. SIAM J. Comput. 2, 106–127 (1973)
Anderson, T., Eve, J., Horning, J.J.: Efficient LR(1) parsers. Acta Informat. 2, 12–39 (1973)
Anderson, T.: Syntactic analysis of LR(k) languages. University of Newcastle upon Tyne, Ph.D. Thesis, 1972
Backhouse, R.C.: An alternative approach to the improvement of LR(k) parsers. Acta Informat. 6, 277–296 (1976)
DeRemer, F.L.: Practical translators for LR(k) languages. Project MAC, Mass. Inst. of Tech., Cambridge, Tech. Report MAC TR-65, October 1969
DeRemer, F.L.: Simple LR(k) grammars. Comm. ACM 14, 453–460 (1971)
Goos, G.: Private communication. Institut für Informatik, Universität Karlsruhe, 1976
Joliat, M.L.: On the reduced matrix representation of LR(k) parser tables. Computer Systems Research Group, University of Toronto, Technical Report SCRG-28, October 1973
Knuth, D.E.: On the translation of languages from left to right. Information and Control 8, 607–639 (1966)
Korenjak, A.J.: A practical method for constructing LR(k) processors. Comm. ACM 12, 618–623 (1969)
Lalonde, W.R.: An efficient LALR parser generator. Computer Systems Research Group, University of Toronto, Tech. Report CSRG-2, 1971
Lalonde, W.R.: On directly constructing LR(k) parsers without chain reductions. Computer Systems Research Group, University of Toronto, Tech. Report, 1975
McKeeman, W.M., Horning, J.J., Wortman, D.B.: A compiler generator. Englewood Cliffs, N.J.: Prentice-Hall 1970
Naur, P., et al.: Revised report on the algorithm language ALGOL 60. Comm. ACM 6, 1–17 (1963)
Pager, D.: A solution to an open problem by Knuth. Information and Control 17, 462–473 (1970)
Pager, D.: The lane tracing algorithm for constructing LR(k) parsers and methods for enhancing its efficiency. Information Sci. 12, 19–42 (1977)
Pager, D.: A practical general method for constructing LR(k) parsers. Acta Informat. 7, 249–268 (1977)
Pager, D.: Compactions made in the parser for a subset of BASIC. Information Sciences Program, University of Hawaii, Honolulu, Tech. Report PE 283, September 1972
Pager, D.: On implementing the revised algorithm for eliminating unit reductions. Information Sciences Program, University of Hawaii, Honolulu, Tech. Report PE 312, January 1973
Pager, D.: On eliminating unit productions from LR(k) parsers. In: Automata, languages, and programming (J. Loeckx, ed.), 2nd Colloquium. Lecture Notes in Computer Science, Vol. 14. Berlin-Heidelberg-New York: Springer 1974
Wirth, N., Hoare, C.A.R.: A contribution to the development of ALGOL. Comm. ACM 9, 413–432 (1966)
Wirth, N., Weber, H.: EULER: A generalization of ALGOL, and its formal definition: Part II. Comm. ACM 9, 89–99 (1966)
Author information
Authors and Affiliations
Additional information
This work was supported by the National Science Foundation under Grant GJ-43362. A shortened version of the paper was presented at the 2nd colloquium on Automata, Languages and Programming, University of Saarbrücken, July 1974
Rights and permissions
About this article
Cite this article
Pager, D. Eliminating unit productions from LR parsers. Acta Informatica 9, 31–59 (1977). https://doi.org/10.1007/BF00263764
Received:
Issue Date:
DOI: https://doi.org/10.1007/BF00263764