Summary
Most applications of parsing require that the parser call semantic action routines while processing the input. For LR(k) parsers it is well known that a semantic action routine can be called when the end of a production is recognized. Often, however, it is desirable to call routines at other times.
This paper presents fast algorithms that determine, for an LR(k) (or SLR(k)) grammar, which positions are suitable for calling routines. The algorithms are practical for use with LR(1) (SLR(1)) parser building programs, because the worst case running time is dominated by the time required to build the LR(1) (SLR(1)) parser. Applications of the algorithms to attribute grammars and automatic indentation are discussed.
Similar content being viewed by others
References
Aho, A.V., Ullman, J.D.: The theory of parsing, translation, and compiling, pp. 368–399. New York: Prentice-Hall 1972
De Remer, F.L.: Practical translation for LR(k) languages. Ph.D. Thesis, MIT, Cambridge, Massachusetts (1969)
Earley, J.: An efficient context-free parsing algorithm. CACM 13, 94–102 (1970)
Knuth, D.E.: On the translation of languages from left to right. Information and Control 8, 607–639 (1965)
Lengauer, T., Tarjan, R.E.: A fast algorithm for finding dominators in a flow graph. TOPLAS 1, 121–141 (1979)
Lowry, E.S., Medlock, C.W.: Object code optimization. CACM 12, 13–22 (1969)
Pager, D.: The lane tracing algorithm for constructing LR(k) parsers and ways of 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)
Purdom, P.: The size of LALR(1) parsers. BIT 14, 326–337 (1974)
Purdom, P.W.: Automatic program indentation. BIT 18, 211–218 (1978)
Tarjan, R.: Depth-first search and linear graph algorithms. SIAM J. Comput. 1, 146–160 (1972)
Watt, D.A.: The parsing problem for affix grammars. Acta Informat. 8, 1–20 (1977)
Author information
Authors and Affiliations
Rights and permissions
About this article
Cite this article
Purdom, P., Brown, C.A. Semantic routines and LR(k) parsers. Acta Informatica 14, 299–315 (1980). https://doi.org/10.1007/BF00286489
Received:
Revised:
Issue Date:
DOI: https://doi.org/10.1007/BF00286489