
Efficient Tabular LR Parsing Mark-Jan Nederhof Giorgio Satta Faculty of Arts Dipartimento di Elettronica ed Informatica University of Groningen Universit£ di Padova P.O. Box 716 via Gradenigo, 6/A 9700 AS Groningen 1-35131 Padova The Netherlands Italy markj an@let, rug. nl satt a@dei, unipd, it Abstract of these automata by means of tabulation yield dif- ferent tabular algorithms for different such construc- We give a new treatment of tabular LR tions. Another example, on which our presentation parsing, which is an alternative to Tomita's is based, was first suggested by Leermakers (1989): generalized LR algorithm. The advantage a grammar is first transformed and then a standard is twofold. Firstly, our treatment is con- tabular algorithm along with some filtering condi- ceptually more attractive because it uses tion is applied using the transformed grammar. In simpler concepts, such as grammar trans- our case, the transformation and the subsequent ap- formations and standard tabulation tech- plication of the tabular algorithm result in a new niques also know as chart parsing. Second- form of tabular LR parsing. ly, the static and dynamic complexity of Our method is more efficient than Tomita's algo- parsing, both in space and time, is signifi- rithm in two respects. First, reduce operations are cantly reduced. implemented in an efficient way, by splitting them in- to several, more primitive, operations (a similar idea 1 Introduction has been proposed by Kipps (1991) for Tomita's al- gorithm). Second, several paths in the computation The efficiency of LR(k) parsing techniques (Sippu that must be simulated separately by Tomita's algo- and Soisalon-Soininen, 1990) is very attractive from rithm are collapsed into a single computation path, the perspective of natural language processing ap- using state minimization techniques. Experiments plications. This has stimulated the computational on practical grammars have indicated that there is linguistics community to develop extensions of these a significant gain in efficiency, with regard to both techniques to general context-free grammar parsing. space and time requirements. The best-known example is generalized LR pars- ing, also known as Tomita's algorithm, described by Our grammar transformation produces a so called Tomita (1986) and further investigated by, for ex- cover for the input grammar, which together with ample, Tomita (1991) and Nederhof (1994a). Des- the filtering condition fully captures the specifica- pite appearances, the graph-structured stacks used tion of the method, abstracting away from algorith- to describe Tomita's algorithm differ very little from mic details such as data structures and control flow. parse fables, or in other words, generalized LR pars- Since this cover can be easily precomputed, imple- ing is one of the so called tabular parsing algorithms, menting our LR parser simply amounts to running among which also the CYK algorithm (Harrison, the standard tabular algorithm. This is very attrac- 1978) and Earley's algorithm (Earley, 1970) can be tive from an application-oriented perspective, since found. (Tabular parsing is also known as chart pars- many actual systems for natural language processing ing.) are based on these kinds of parsing algorithm. In this paper we investigate the extension of LR The remainder of this paper is organized as fol- parsing to general context-free grammars from a lows. In Section 2 some preliminaries are discussed. more general viewpoint: tabular algorithms can of- We review the notion of LR automaton in Section.3 ten be described by the composition of two construc- and introduce the notion of 2LR automaton in Sec- tions. One example is given by Lang (1974) and tion 4. Then we specify our tabular LR method in Billot and Lang (1989): the construction of push- Section 5, and provide an analysis of the algorithm down automata from grammars and the simulation in Section 6. Finally, some empirical results are giv- 239 en in Section 7, and further discussion of our method The application of a transition 81 ~-~ 82 is de- is provided in Section 8. scribed as follows. If the top-most symbols of the stack are 61, then these symbols may be replaced by 2 Definitions 62, provided that either z = e, or z = a and a is the first symbol of the remaining input. Furthermore, if Throughout this paper we use standard formal lan- z = a then a is removed from the remaining input. guage notation. We assume that the reader is famil- Formally, for a fixed PDA .4 we define the bina- iar with context-free grammar parsing theory (Har- ry relation t- on configurations as the least relation rison, 1978). satisfying (881, w) ~- (662, w) if there is a transition A context-free grammar (CFG) is a 4-tuple G = 61 ~ 62, and (881, aw) t- (682, w) if there is a tran- (S, N, P, S), where S and N are two finite disjoint sition 61 a 82. The recognition of a certain input v sets of terminal and nonterminal symbols, respec- is obtained if starting from the initial configuration tively, S E N is the start symbol, and P is a finite for that input we can reach the final configuration set of rules. Each rule has the form A ---* a with by repeated application of transitions, or, formally, A E N and a E V*, where V denotes N U E. The if (qin, v) I"* (q~,, aria, e), where t-* denotes the re- size of G, written I G I, is defined as I; E(A--*a)EP [Aot flexive and transitive closure of b. by I a I we mean the length of a string of symbols a. By a computation of a PDA we mean a sequence We generally use symbols A,B,C,... to range (qi,,v) t- (61,wl) h... t- (6n,wn), n > 0. A PDA is over N, symbols a, b, c,... to range over S, symbols called deterministic if for all possible configurations X, Y, Z to range over V, symbols ~, 8, 7,... to range at most one transition is applicable. A PDA is said over V*, and symbols v, w, z,... to range over S*. to be in binary form if, for all transitions 61 ~L~ 62, We write e to denote the empty string. we have 1611 < 2. A CFG is said to be in binary form if ~ E {e} U V t.J N 2 for all of its rules A --* c~. (The binary 3 Ll:t automata form does not limit the (weak) generative capaci- ty of context-free grammars (Harrison, 1978).) For Let G = (S, N, P, S) be a CFG. We recall the no- technicM reasons, we sometimes use the augment- tion of LR automaton, which is a particular kind ed grammar associated with G, defined as G t = of PDA. We make use of the augmented grammar (St, N t, pt, St), where St, t> and <1 are fresh sym- G t = (st, N t, pt, S t) introduced in Section 2. bols, S t = SU {t>,<l}, N t = NU {S t } and Let !LR : {A ~ a • ~ I (A --~ aft) E pt}. pt = p U {S t ~ t>S<~}. We introduce the function closure from 2 I~'R to 2 ILR A pushdown automaton (PDA) is a 5-tuple .4 = and the function goto from 2 ILR × V to 2 l~rt. For (Z, Q, T, qi,, q/in), where S, Q and T are finite sets any q C ILK, closure(q) is the smallest set such that of input symbols, stack symbols and transitions, re- spectively; qin E Q is the initiM stack symbol and (i) q c closure(q); and q/i, E Q is the finM stack symbol. 1 Each transition (ii) (B --~ c~ • Aft) e closure(q) and (A ~ 7) e pt has the form 61 ~-~ 62, where 61,82 E Q*, 1 < 161 l, together imply (A --* • 7) E closure(q). 1 < 1621 < 2, and z = e or z = a. We generally use symbols q, r, s,... to range over Q, and the symbol We then define 6 to range over Q*. Consider a fixed input string v E ~*. A config- goto(q, X) = uration of the automaton is a pair (6, w) consisting {A ---* ~X • fl I (A --* a • Xfl) E closure(q)}. of a stack 6 E Q* and the remaining input w, which is a suffix of the input string v. The rightmost sym- We construct a finite set T~Lp~ as the smallest collec- bol of 6 represents the top of the stack. The initial tion of sets satisfying the conditions: configuration has the form (qi~, v), where the stack is formed by the initial stack symbol. The final con- (i) {S t ~ t>. S<~} E ~'~Ll=t; and figuration has the form (qi, q/i,, e), where the stack is formed by the final stack symbol stacked upon the (ii) for every q E ~T~LR and X E V, we have initial stack symbol. goto(q, X) E 7~LR, provided goto(q, X) ~ 0. ZWe dispense with the notion of state, traditionally Two elements from ~Lt~ deserve special attention: incorporated in the definition of PDA. This does not qm = {S t --+ t> * S<~}, and q/in, which is defined to affect the power of these devices, since states can be be the unique set in "~Ll:t containing (S t ~ t>S * <~); encoded within stack symbols and transitions. in other words, q/in = goto(q~n, S). 240 For A • N, an A-redex is a string qoqlq2"" "qm, Nederhof (1994a), and for LR parsing specifically m _> 0, of elements from T~Lrt, satisfying the follow- gipps (1991) and Leermakers (19925).) The follow- ing conditions: ing definition introduces this new kind of automaton.
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages8 Page
-
File Size-