Abstract

One of the most attractive techniques in optimizing LR parsers is to eliminate reductions by semantically insignificant productions of the form A → X (single productions), where X is a nonterminal or a terminal; such a modification can lead to substantial savings in both space and time. Therefore, much effort has been devoted to the development of methods for eliminating reductions 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 which all reductions by single productions can be eliminated from LR parsers, but their method may produce a considerable increase in the number of states in the parser. On the other hand, with the techniques of Aho and Ullman[1973b] and Demers[1975] no increase in the number of states can occur, but the elimination of reductions by single productions is guaranteed only if no two single productions have the same left hand side. Pager[1973a,1974] has extended the method of Aho and Ullman[1973b] so that all reductions by single productions are eliminated. LaLonde[1976] and Backhouse[1976] consider versions of the method of Pager, and Joliat[1976] considers a method which is essentially that given by Anderson, Eve and Horning[1973] as a suggestion for simplifying their general technique. In Anderson, Eve and Horning[1973] the elimination of reductions by single productions is performed during the construction of the LR parser, whereas in Aho and Ullman[1973b] and in Pager [1973a,1974] reductions by single productions are eliminated after construction of the parser. Demers [1975] considers versions of Aho and Ullman's method such that elimination can be performed both during and after construction of the parser, and LaLonde[1976] describes a version of Pager's method by which reductions by single productions can be eliminated during parser construction. Except the method of Anderson, Eve and Horning [1973] all the above techniques rely heavily on the fact that in LR parsing certain error entries can never be consulted. However, dependence upon these entries leads to some difficulties in the practical use of the techniques. First, they may not be applicable for all types of LR parsers: the method of Pager[1973a,1974] produces a parser which accepts exactly the strings in the language in the case of canonical (Knuth[1965]) and SLR (DeRemer[1971]) parsers but may produce a parser which accepts erroneous strings in the 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 other parser optimizations may decrease the number of don't care entries, and these optimizations need special treatment if they are to be applied in conjunction with the elimination of reductions by single productions. One well known method for optimizing LR parsers, which is extremely useful especially in list representation of LR parsers and which may decrease the number of don't care entries is the use of default reductions (if one or more reduce actions are possible in some state then one of these reduce actions is chosen for the default 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 with the elimination of reductions by single productions is discussed in Pager[1973a] and a method is given there to solve the problem. The basis of the solution is to apply first the algorithm for eliminating reductions by single productions and then to check every potential default reduction in order to decide whether it can be used or not. Hence, in the optimized parser all reductions by single productions are eliminated, but the use of default reductions can be limited. (Pager [1973a] has found that in the case of some practical grammars almost all of potential default reductions can be used.) In the present paper we consider another approach to the problem. In our method the elimination process itself corresponds to the technique of Pager[1973a,1974], but the elimination is carried out only if it does not affect the applicability of default reductions. The main motivation of this approach is the fact that it leads to a method for eliminating reductions by single productions 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 2 contains some terminology and a brief review of the theory of LR parsing. In section 3 we consider the method of Pager[1973a,1974] in a form similar to that given by LaLonde[1976] and show by an example that the method may produce invalid parsers in the case of the LALR construction. Finally, our method for eliminating reductions by single productions in conjunction with the use of default reductions is given in section 4.

Talk to us

Join us for a 30 min session where you can share your feedback and ask us any queries you have

Schedule a call

Disclaimer: All third-party content on this website/platform is and will remain the property of their respective owners and is provided on "as is" basis without any warranties, express or implied. Use of third-party content does not indicate any affiliation, sponsorship with or endorsement by them. Any references to third-party content is to identify the corresponding services and shall be considered fair use under The CopyrightLaw.