Elimination of single productions from LR parsers in conjunction with the use of default reductions

  • Authors:
  • Eljas Soisalon-Soininen

  • Affiliations:
  • University of Helsinki, Töölönkatu 11, SF-0010 Helsinki 10, Finland

  • Venue:
  • POPL '77 Proceedings of the 4th ACM SIGACT-SIGPLAN symposium on Principles of programming languages
  • Year:
  • 1977

Quantified Score

Hi-index 0.00

Visualization

Abstract

One of the most attractive techniques in optimizing LR parsersis to eliminate reductions by semantically insignificantproductions of the form A → X (single productions), where X isa nonterminal or a terminal; such a modification can lead tosubstantial savings in both space and time. Therefore, much efforthas been devoted to the development of methods for eliminatingreductions by single productions from LR parsers (Aho and Ullman[1973a,1973b], Anderson, Eve and Horning[1973], Pager[1973a,1974],Demers[1974,1975], Backhouse [1976], Joliat[1976], Koskimies[1976],LaLonde [1976], Soisalon-Soininen[1976]).Anderson, Eve and Horning[1973] have described a method by whichall reductions by single productions can be eliminated from LRparsers, but their method may produce a considerable increase inthe number of states in the parser. On the other hand, with thetechniques of Aho and Ullman[1973b] and Demers[1975] no increase inthe number of states can occur, but the elimination of reductionsby single productions is guaranteed only if no two singleproductions have the same left hand side. Pager[1973a,1974] hasextended the method of Aho and Ullman[1973b] so that all reductionsby single productions are eliminated. LaLonde[1976] andBackhouse[1976] consider versions of the method of Pager, andJoliat[1976] considers a method which is essentially that given byAnderson, Eve and Horning[1973] as a suggestion for simplifyingtheir general technique.In Anderson, Eve and Horning[1973] the elimination of reductionsby single productions is performed during the construction of theLR parser, whereas in Aho and Ullman[1973b] and in Pager[1973a,1974] reductions by single productions are eliminated afterconstruction of the parser. Demers [1975] considers versions of Ahoand Ullman's method such that elimination can be performed bothduring and after construction of the parser, and LaLonde[1976]describes a version of Pager's method by which reductions by singleproductions can be eliminated during parser construction.Except the method of Anderson, Eve and Horning [1973] all theabove techniques rely heavily on the fact that in LR parsingcertain error entries can never be consulted. However, dependenceupon these "don't care" entries leads to some difficulties in thepractical use of the techniques. First, they may not be applicablefor all types of LR parsers: the method of Pager[1973a,1974]produces a parser which accepts exactly the strings in the languagein the case of canonical (Knuth[1965]) and SLR (DeRemer[1971])parsers but may produce a parser which accepts erroneous strings inthe case of LALR parsers (used e.g. by LaLonde[1971],Johnson[1975], Joliat[1975]) and generalizations of them (Pager[1973b,1975], Soisalon-Soininen[1975]). Furthermore, certain otherparser optimizations may decrease the number of don't care entries,and these optimizations need special treatment if they are to beapplied in conjunction with the elimination of reductions by singleproductions. One well known method for optimizing LR parsers, whichis extremely useful especially in list representation of LR parsersand which may decrease the number of don't care entries is the useof default reductions (if one or more reduce actions are possiblein some state then one of these reduce actions is chosen for thedefault reduction which is performed instead of reporting error;see Pager[1973a], Aho and Johnson[1974], Horning[1974],Aho[1976]).The problem in the use of default reductions in conjunction withthe elimination of reductions by single productions is discussed inPager[1973a] and a method is given there to solve the problem. Thebasis of the solution is to apply first the algorithm foreliminating reductions by single productions and then to checkevery potential default reduction in order to decide whether it canbe used or not. Hence, in the optimized parser all reductions bysingle productions are eliminated, but the use of defaultreductions can be limited. (Pager [1973a] has found that in thecase of some practical grammars almost all of potential defaultreductions can be used.)In the present paper we consider another approach to theproblem. In our method the elimination process itself correspondsto the technique of Pager[1973a,1974], but the elimination iscarried out only if it does not affect the applicability of defaultreductions. The main motivation of this approach is the fact thatit leads to a method for eliminating reductions by singleproductions which is applicable for any type of LR parser,including LALR parsers and generalizations of them.The rest of the present paper is organized as follows. Section 2contains some terminology and a brief review of the theory of LRparsing. In section 3 we consider the method of Pager[1973a,1974]in a form similar to that given by LaLonde[1976] and show by anexample that the method may produce invalid parsers in the case ofthe LALR construction. Finally, our method for eliminatingreductions by single productions in conjunction with the use ofdefault reductions is given in section 4.