Abstract
This chapter is devoted to the practical issues involved in the construction and use of deterministic LR(1) parsers. We shall show how the practical versions of LR (1) parsers, most notably the LALR (1) parsers, can be constructed efficiently, and we shall present methods for encoding LR(1) parsers as efficient RAM programs. Two versions of RAM program implementation are considered: in the first implementation the parsing program is table-driven, that is, the rules of the parser are encoded in a two-dimensional array which is simulated by a program body; in the other implementation the tabular information is further transformed into a set of program statements.
This is a preview of subscription content, log in via an institution.
Buying options
Tax calculation will be finalised at checkout
Purchases are for personal use only
Learn about institutional subscriptionsPreview
Unable to display preview. Download preview PDF.
Bibliographic Notes
LaLonde (1971) was the first to design an efficient algorithm for constructing LALR(1) parsers. Later on, many implementations for the construction of LALR(1) lookahead sets have been presented, among which the most prominent are the algorithms by Kristensen and Madsen (1981), DeRemer and Pennello (1982), Park, Choe and Chang (1985), and Bermudez and Logothetis (1989). Our presentation follows DeRemer and Pennello (1982) (also see Sager, 1986).
The table-driven implementation of LR(1) parsers originates from Knuth (1965). Encoding the parsing tables as program statements has been suggested e.g. by Aho and Johnson (1974) and Aho and Ullman (1977). The use of default reductions and the elimination of unique reduce states have been suggested in several sources, perhaps first by DeRemer (1969). The method for subsuming rows in a parsing program considered in Exercises 7.22 to 7.25 originates from Ichbiah and Morse (1970), who used it for precedence parser optimization.
Algorithms for determining inessential error entries in the parsing table for canonical LR(1) and SLR(1) parsers have been devised by Aho and Ullman (1972a, 1973a, 1973b). Soisalon-Soininen (1982) presented an algôrithm for determining inessential error entries for any LR (0)-based LR(1) parser. The first efficient algorithm for determining all inessential error entries for any LR(0)-based LR(1) parser is given in Sippu and Soisalon-Soininen (1985). Joliat (1973, 1974) was the first to suggest the error matrix factoring from the parsing table, thus making all error entries inessential. This approach is favored by Dencker, Durre and Heuft (1984) based on a detailed experimental analysis. Determining the true inessential error entries remains important, however, for the compression of the error matrix and for the elimination of reductions by unit rules.
The idea of making use of inessential error entries in parsing table compression comes from Pager (1970), who, however, considered all error entries inessential and thus sacrificed some essential features of LR(k) parsing: the correctness of the parser was preserved by storing the stack string in the parsing stack and by matching the stack string with the right-hand side of the rule by which a reduce action was to be performed. Pager’s idea was used by Aho and Ullman (1972a, 1973a) and by Joliat (1973, 1974) but now retaining the properties of LR(k) parsing. The approximation algorithm for graph coloring given in Figure 7.32 and its use for parsing table compression was proposed by Dencker et al. (1984).
The elimination of reductions by unit rules has been studied in many sources, e.g. Anderson, Eve and Horning (1973), Aho and Ullman (1973a, 1973b), Demers (1974, 1975), Pager (1974, 1977b), LaLonde (1976a), Soisalon-Soininen (1977a,
1980a, 1982), Koskimies and Soisalon-Soininen (1979), Rushby (1977), Tokuda (1981), Drossopoulou (1982), Schmitz (1984), LaLonde (1984), and by Heilbrunner (1985). The algorithm given in Figure 7.37 is the one suggested by Aho and Ullman (1973b), and the algorithm of Figure 7.40 is from Anderson et al. (1973). The method indicated in Exercise 7.48 for SLR(1) parsers is the basic method of Pager (1974, 1977b). In the work of Rushby (1977) the whole LR(k) theory is developed in conjunction with unit rule elimination. Drossopoulou (1982) considers the general question of combining consecutive reduce actions.
LR(k) parsing of ambiguous grammars is considered in Demers (1974) and in Aho, Johnson and Ullman (1975). Johnson (1975) describes a compiler writing system that employs ambiguous grammars with disambiguating rules; also see Aho and Ullman (1977) and Aho, Sethi and Ullman (1986). The formalism for disambiguating rules used in Section 7.6 is from Koskimies, Paakki, Nurmi and Sippu (1988).
Finally we would like to mention the work of Pager (1977a) which generalizes in a practical way the construction of LALR(1) parsers to produce a deterministic LR(1) parser for any LR(1) grammar. Heilbrunner (1981) formalizes this and other algorithms for constructing LR(1) parsers.
Author information
Authors and Affiliations
Rights and permissions
Copyright information
© 1990 Springer-Verlag Berlin Heidelberg
About this chapter
Cite this chapter
Sippu, S., Soisalon-Soininen, E. (1990). Construction and Implementation of LR(1) Parsers. In: Parsing Theory. EATCS, vol 20. Springer, Berlin, Heidelberg. https://doi.org/10.1007/978-3-662-08424-3_2
Download citation
DOI: https://doi.org/10.1007/978-3-662-08424-3_2
Publisher Name: Springer, Berlin, Heidelberg
Print ISBN: 978-3-642-08079-1
Online ISBN: 978-3-662-08424-3
eBook Packages: Springer Book Archive