Skip to main content
Log in

Eliminating unit productions from LR parsers

  • Published:
Acta Informatica Aims and scope Submit manuscript

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].

This is a preview of subscription content, log in via an institution to check access.

Access this article

Subscribe and save

Springer+ Basic
$34.99 /Month
  • Get 10 units per month
  • Download Article/Chapter or eBook
  • 1 Unit = 1 Article or 1 Chapter
  • Cancel anytime
Subscribe now

Buy Now

Price excludes VAT (USA)
Tax calculation will be finalised during checkout.

Instant access to the full article PDF.

Similar content being viewed by others

References

  1. Aho, A.V., Ullman, J.D.: The theory of parsing, translation and compiling. Englewood Cliffs, N.J.: Prentice-Hall 1973

    Google Scholar 

  2. Aho, A.V., Ullman, J.D.: Optimization of LR(k) parsers. J. Comput. System Sci. 6, 573–602 (1972)

    CAS  PubMed  Google Scholar 

  3. Aho, A.V., Ullman, J.D.: A technique for speeding up LR(k) parsers. SIAM J. Comput. 2, 106–127 (1973)

    Google Scholar 

  4. Anderson, T., Eve, J., Horning, J.J.: Efficient LR(1) parsers. Acta Informat. 2, 12–39 (1973)

    Google Scholar 

  5. Anderson, T.: Syntactic analysis of LR(k) languages. University of Newcastle upon Tyne, Ph.D. Thesis, 1972

  6. Backhouse, R.C.: An alternative approach to the improvement of LR(k) parsers. Acta Informat. 6, 277–296 (1976)

    Google Scholar 

  7. DeRemer, F.L.: Practical translators for LR(k) languages. Project MAC, Mass. Inst. of Tech., Cambridge, Tech. Report MAC TR-65, October 1969

    Google Scholar 

  8. DeRemer, F.L.: Simple LR(k) grammars. Comm. ACM 14, 453–460 (1971)

    Google Scholar 

  9. Goos, G.: Private communication. Institut für Informatik, Universität Karlsruhe, 1976

  10. 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

  11. Knuth, D.E.: On the translation of languages from left to right. Information and Control 8, 607–639 (1966)

    Google Scholar 

  12. Korenjak, A.J.: A practical method for constructing LR(k) processors. Comm. ACM 12, 618–623 (1969)

    Google Scholar 

  13. Lalonde, W.R.: An efficient LALR parser generator. Computer Systems Research Group, University of Toronto, Tech. Report CSRG-2, 1971

  14. Lalonde, W.R.: On directly constructing LR(k) parsers without chain reductions. Computer Systems Research Group, University of Toronto, Tech. Report, 1975

  15. McKeeman, W.M., Horning, J.J., Wortman, D.B.: A compiler generator. Englewood Cliffs, N.J.: Prentice-Hall 1970

    Google Scholar 

  16. Naur, P., et al.: Revised report on the algorithm language ALGOL 60. Comm. ACM 6, 1–17 (1963)

    Google Scholar 

  17. Pager, D.: A solution to an open problem by Knuth. Information and Control 17, 462–473 (1970)

    Google Scholar 

  18. Pager, D.: The lane tracing algorithm for constructing LR(k) parsers and methods for enhancing its efficiency. Information Sci. 12, 19–42 (1977)

    Google Scholar 

  19. Pager, D.: A practical general method for constructing LR(k) parsers. Acta Informat. 7, 249–268 (1977)

    Google Scholar 

  20. 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

    Google Scholar 

  21. Pager, D.: On implementing the revised algorithm for eliminating unit reductions. Information Sciences Program, University of Hawaii, Honolulu, Tech. Report PE 312, January 1973

    Google Scholar 

  22. 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

    Google Scholar 

  23. Wirth, N., Hoare, C.A.R.: A contribution to the development of ALGOL. Comm. ACM 9, 413–432 (1966)

    Google Scholar 

  24. Wirth, N., Weber, H.: EULER: A generalization of ALGOL, and its formal definition: Part II. Comm. ACM 9, 89–99 (1966)

    Google Scholar 

Download references

Author information

Authors and Affiliations

Authors

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

Reprints 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

Download citation

  • Received:

  • Issue Date:

  • DOI: https://doi.org/10.1007/BF00263764

Keywords