On directly constructing LR(k) parsers without chain reductions (original) (raw)
Related papers
Journal of Computer and System Sciences, 1972
Certain techniques for modifying LR(k) parsing tables to decrease their size have been developed by Korenjak [2] and DeRemer . We show that the techniques of the latter can be characterized by two transformations on sets of tables. We then show that the "simple" LR(1) method of DeRemer [4] can be considered a special case of Korenjak's method .
An alternative approach to the improvement of LR(k) parsers
Acta Informatica, 1976
Korenjak are shown to be based on a single concept--that of modifying the contextual information on which parsing decisions axe made. This concept is then used to derive a straightforward algorithm for eliminating unit productions from an LR parser.
Semantic routines and LR(k) parsers
Acta Informatica, 1980
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.
Construction of efficient generalized LR parsers
Automata Implementation, 1998
We show how LR parsers for the analysis of arbitrary context free grammars can be derived from classical Earley's parsing algorithm. The result is a Generalized LR parsing algorithm working at complexity O(n^3) in the worst case, which is achieved by the use of dynamic programming to represent the non-deterministic evolution of the stack instead of graph-structured stack representations, as has often been the case in previous approaches. The algorithm behaves better in practical cases, achieving linear complexity on LR
A new parsing method for non-LR(1) grammars
Software: Practice and Experience, 1992
Ow of the difficult problems that faces a compiler writer is to devise a grammar that is suitable for both eflkient parsing and semantic attribution. This paper describes a system that resolves conflirts in LR(1) parsing by taking advantage of information in the parse tree. The system, which functions as part of a compiler generator, rewrites the user's grammar to remove parsing contlicts. It then places code into the generated compiler that rewrites the parse tree during parsing so as to produce the tree of the original grammar. The compiler writer can then write the semantic attribution to fit hi or her original grammar without any knowledge of the changes made. The method is expected to be ef6cient in most cases, even in parsing systems that do not explicitly build the entire parse tree. The method complements previous work in its capabilities and advantages. The system has been implemented and integrated into a compiler generator system.
A New Approach to the Construction of Generalized LR Parsing Algorithms
We present a Generalized LR parsing algorithm for unrestricted context-free grammars working in complexity O(n 3 ). It differs from previous approaches in the use of dynamic programming techniques to cope with the non determinism, instead of a graph-structured stack. The steps for deriving our algorithm from classical Earley's parsing algorithm are shown.
Generation of LR parsers by partial evaluation
ACM Transactions on Programming Languages and Systems, 2000
The combination of modern programming languages and partial evaluation yields new approaches to old problems. In particular, the combination of functional programming and partial evaluation can turn a general parser into a parser generator. We use an inherently functional approach to implement general LR(k) parsers and specialize them with respect to the input grammars using offline partial evaluation. The functional specification of LR parsing yields a concise implementation of the algorithms themselves. Furthermore, we demonstrate the elegance of the functional approach by incorporating on-the-fly attribute evaluation for S-attributed grammars and two schemes for error recovery, which lend themselves to natural and elegant implementation. The parsers require only minor changes to achieve good specialization results. The generated parsers have production quality and match those produced by traditional parser generators in speed and compactness.
The Use of Predicates In LL(k) And LR(k) Parser Generators (Technical Summary)
Although existing LR(1) or U(1) parser generators suffice for many language recognition problems, writing a straightforward grammar to translate a complicated language, such as C++ or even C, remains a non-trivial task. We have often found that adding translation actions to the grammar is harder than writing the grammar itself. Part of the problem is that many languages are context-sensitive. Simple, natural descriptions of these languages escape current language tool technology because they were not designed to handle semantic information. In this paper, we introduce predicated LR (k) and LL (k) parsers as a solution. Predicates provide a general, practical means to utilize semantic tests in parsers. Used in conjunction with k >1 lookahead sets, a predicated parser simplifies the task of writing real translators. Our approach differs from previous work in that (i) we allow multiple predicates to be placed arbitrarily within a production, (ii) we describe the construction of pred...
Computer Languages, Systems & Structures - CL, 1988
SL, the Syntax Language component of S/SL (Syntax/Semantic Language) is a dataless programming language for implementing efficient recursive descent parsers. SL is clearly powerful enough to parse the LL(1) languages, but it is much less obvious that it is sufficiently powerful to parse the LR(k) languages. We show that this is in fact the case by giving an algorithm to construct an SL program that parses the same language as a given LR(1) parser. This construction provides both a proof that SL has the parsing power of LR(1) [and hence LR(k)] and a practical method for deriving efficient SL parsers from BNF grammars.