A New Approach to the Construction of Generalized LR Parsing Algorithms

LR parsing strategies can analyze LR grammars, which are deterministic. If we consider LR parsing tables in which each entry can contain several actions, we obtain non-deterministic LR parsing, often known as generalized LR parsing, which can analyze non-deterministic context-free grammars. It this context, some mechanism is needed in order to represent the non-deterministic evolution of the stack. Tomita (Tomita 86) have proposed an algorithm based on a graph-structured stack but it has problems with cyclic and hidden left recursive constructions. Rekers (Rekers 92) has modified the original algorithm to overcome its limitations, but maintaining its original complexity O(np+1), where p is the length of the longer right-hand side of a rule. Space and time bounds can be reduced transforming the form of the grammar (Sheil 76). Some approaches also use transformations in the construction of the LR automaton and in these the treatment of cyclicity is even more complex and so is often avoided (Nederhof & Sarbo 93). We propose a generalized LR(1) and LALR(1) parsing algorithm for arbitrary context-free grammars which is derived, in a natural way, from the well known Earley’s algorithm (Earley 70), preserving cubic time complexity in the worst case.