Efficient Tabular L R Parsing

Total Page:16

File Type:pdf, Size:1020Kb

Efficient Tabular L R Parsing 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.
Recommended publications
  • The Earley Algorithm Is to Avoid This, by Only Building Constituents That Are Compatible with the Input Read So Far
    Earley Parsing Informatics 2A: Lecture 21 Shay Cohen 3 November 2017 1 / 31 1 The CYK chart as a graph What's wrong with CYK Adding Prediction to the Chart 2 The Earley Parsing Algorithm The Predictor Operator The Scanner Operator The Completer Operator Earley parsing: example Comparing Earley and CYK 2 / 31 We would have to split a given span into all possible subspans according to the length of the RHS. What is the complexity of such algorithm? Still O(n2) charts, but now it takes O(nk−1) time to process each cell, where k is the maximal length of an RHS. Therefore: O(nk+1). For CYK, k = 2. Can we do better than that? Note about CYK The CYK algorithm parses input strings in Chomsky normal form. Can you see how to change it to an algorithm with an arbitrary RHS length (of only nonterminals)? 3 / 31 Still O(n2) charts, but now it takes O(nk−1) time to process each cell, where k is the maximal length of an RHS. Therefore: O(nk+1). For CYK, k = 2. Can we do better than that? Note about CYK The CYK algorithm parses input strings in Chomsky normal form. Can you see how to change it to an algorithm with an arbitrary RHS length (of only nonterminals)? We would have to split a given span into all possible subspans according to the length of the RHS. What is the complexity of such algorithm? 3 / 31 Note about CYK The CYK algorithm parses input strings in Chomsky normal form.
    [Show full text]
  • LATE Ain't Earley: a Faster Parallel Earley Parser
    LATE Ain’T Earley: A Faster Parallel Earley Parser Peter Ahrens John Feser Joseph Hui [email protected] [email protected] [email protected] July 18, 2018 Abstract We present the LATE algorithm, an asynchronous variant of the Earley algorithm for pars- ing context-free grammars. The Earley algorithm is naturally task-based, but is difficult to parallelize because of dependencies between the tasks. We present the LATE algorithm, which uses additional data structures to maintain information about the state of the parse so that work items may be processed in any order. This property allows the LATE algorithm to be sped up using task parallelism. We show that the LATE algorithm can achieve a 120x speedup over the Earley algorithm on a natural language task. 1 Introduction Improvements in the efficiency of parsers for context-free grammars (CFGs) have the potential to speed up applications in software development, computational linguistics, and human-computer interaction. The Earley parser has an asymptotic complexity that scales with the complexity of the CFG, a unique, desirable trait among parsers for arbitrary CFGs. However, while the more commonly used Cocke-Younger-Kasami (CYK) [2, 5, 12] parser has been successfully parallelized [1, 7], the Earley algorithm has seen relatively few attempts at parallelization. Our research objectives were to understand when there exists parallelism in the Earley algorithm, and to explore methods for exploiting this parallelism. We first tried to naively parallelize the Earley algorithm by processing the Earley items in each Earley set in parallel. We found that this approach does not produce any speedup, because the dependencies between Earley items force much of the work to be performed sequentially.
    [Show full text]
  • Lecture 10: CYK and Earley Parsers Alvin Cheung Building Parse Trees Maaz Ahmad CYK and Earley Algorithms Talia Ringer More Disambiguation
    Hack Your Language! CSE401 Winter 2016 Introduction to Compiler Construction Ras Bodik Lecture 10: CYK and Earley Parsers Alvin Cheung Building Parse Trees Maaz Ahmad CYK and Earley algorithms Talia Ringer More Disambiguation Ben Tebbs 1 Announcements • HW3 due Sunday • Project proposals due tonight – No late days • Review session this Sunday 6-7pm EEB 115 2 Outline • Last time we saw how to construct AST from parse tree • We will now discuss algorithms for generating parse trees from input strings 3 Today CYK parser builds the parse tree bottom up More Disambiguation Forcing the parser to select the desired parse tree Earley parser solves CYK’s inefficiency 4 CYK parser Parser Motivation • Given a grammar G and an input string s, we need an algorithm to: – Decide whether s is in L(G) – If so, generate a parse tree for s • We will see two algorithms for doing this today – Many others are available – Each with different tradeoffs in time and space 6 CYK Algorithm • Parsing algorithm for context-free grammars • Invented by John Cocke, Daniel Younger, and Tadao Kasami • Basic idea given string s with n tokens: 1. Find production rules that cover 1 token in s 2. Use 1. to find rules that cover 2 tokens in s 3. Use 2. to find rules that cover 3 tokens in s 4. … N. Use N-1. to find rules that cover n tokens in s. If succeeds then s is in L(G), else it is not 7 A graphical way to visualize CYK Initial graph: the input (terminals) Repeat: add non-terminal edges until no more can be added.
    [Show full text]
  • A Mobile App for Teaching Formal Languages and Automata
    Received: 21 December 2017 | Accepted: 19 March 2018 DOI: 10.1002/cae.21944 SPECIAL ISSUE ARTICLE A mobile app for teaching formal languages and automata Carlos H. Pereira | Ricardo Terra Department of Computer Science, Federal University of Lavras, Lavras, Brazil Abstract Formal Languages and Automata (FLA) address mathematical models able to Correspondence Ricardo Terra, Department of Computer specify and recognize languages, their properties and characteristics. Although Science, Federal University of Lavras, solid knowledge of FLA is extremely important for a B.Sc. degree in Computer Postal Code 3037, Lavras, Brazil. Science and similar fields, the algorithms and techniques covered in the course Email: [email protected] are complex and difficult to assimilate. Therefore, this article presents FLApp, Funding information a mobile application—which we consider the new way to reach students—for FAPEMIG (Fundação de Amparo à teaching FLA. The application—developed for mobile phones and tablets Pesquisa do Estado de Minas Gerais) running Android—provides students not only with answers to problems involving Regular, Context-free, Context-Sensitive, and Recursively Enumer- able Languages, but also an Educational environment that describes and illustrates each step of the algorithms to support students in the learning process. KEYWORDS automata, education, formal languages, mobile application 1 | INTRODUCTION In this article, we present FLApp (Formal Languages and Automata Application), a mobile application for teaching FLA Formal Languages and Automata (FLA) is an important area that helps students by solving problems involving Regular, of Computer Science that approaches mathematical models Context-free, Context-Sensitive, and Recursively Enumerable able to specify and recognize languages, their properties and Languages (levels 3 to 0, respectively), in addition to create an characteristics [14].
    [Show full text]
  • An Earley Parsing Algorithm for Range Concatenation Grammars
    An Earley Parsing Algorithm for Range Concatenation Grammars Laura Kallmeyer Wolfgang Maier Yannick Parmentier SFB 441 SFB 441 CNRS - LORIA Universitat¨ Tubingen¨ Universitat¨ Tubingen¨ Nancy Universite´ 72074 Tubingen,¨ Germany 72074 Tubingen,¨ Germany 54506 Vandœuvre, France [email protected] [email protected] [email protected] Abstract class of LCFRS has received more attention con- cerning parsing (Villemonte de la Clergerie, 2002; We present a CYK and an Earley-style Burden and Ljunglof,¨ 2005). This article proposes algorithm for parsing Range Concatena- new CYK and Earley parsers for RCG, formulat- tion Grammar (RCG), using the deduc- ing them in the framework of parsing as deduction tive parsing framework. The characteris- (Shieber et al., 1995). The second section intro- tic property of the Earley parser is that we duces necessary definitions. Section 3 presents a use a technique of range boundary con- CYK-style algorithm and Section 4 extends this straint propagation to compute the yields with an Earley-style prediction. of non-terminals as late as possible. Ex- periments show that, compared to previ- 2 Preliminaries ous approaches, the constraint propagation The rules (clauses) of RCGs1 rewrite predicates helps to considerably decrease the number ranging over parts of the input by other predicates. of items in the chart. E.g., a clause S(aXb) S(X) signifies that S is → 1 Introduction true for a part of the input if this part starts with an a, ends with a b, and if, furthermore, S is also true RCGs (Boullier, 2000) have recently received a for the part between a and b.
    [Show full text]
  • Principles and Implementation of Deductive Parsing
    Principles and implementation of deductive parsing The Harvard community has made this article openly available. Please share how this access benefits you. Your story matters Citation Stuart M. Shieber, Yves Schabes, and Fernando C. N. Pereira. Principles and implementation of deductive parsing. Journal of Logic Programming, 24(1-2):3-36, July-August 1995. Also available as cmp-lg/9404008. Published Version http://dx.doi.org/10.1016/0743-1066(95)00035-I Citable link http://nrs.harvard.edu/urn-3:HUL.InstRepos:2031716 Terms of Use This article was downloaded from Harvard University’s DASH repository, and is made available under the terms and conditions applicable to Other Posted Material, as set forth at http:// nrs.harvard.edu/urn-3:HUL.InstRepos:dash.current.terms-of- use#LAA J. LOGIC PROGRAMMING 1995:24(1{2):3{36 3 PRINCIPLES AND IMPLEMENTATION OF DEDUCTIVE PARSING STUART M. SHIEBER, YVES SCHABES, ∗ AND FERNANDO C. N. PEREIRAy £ We present a system for generating parsers based directly on the metaphor of parsing as deduction. Parsing algorithms can be represented directly as deduction systems, and a single deduction engine can interpret such de- duction systems so as to implement the corresponding parser. The method generalizes easily to parsers for augmented phrase structure formalisms, such as definite-clause grammars and other logic grammar formalisms, and has been used for rapid prototyping of parsing algorithms for a variety of formalisms including variants of tree-adjoining grammars, categorial gram- mars, and lexicalized context-free grammars. ¡ 1. INTRODUCTION Parsing can be viewed as a deductive process that seeks to prove claims about the grammatical status of a string from assumptions describing the grammatical properties of the string's elements and the linear order between them.
    [Show full text]
  • Analysis of Cocke-Younger-Kasami and Earley Algorithms on Probabilistic Context-Free Grammar
    International Research Journal of Engineering and Technology (IRJET) e-ISSN: 2395-0056 Volume: 06 Issue: 10 | Oct 2019 www.irjet.net p-ISSN: 2395-0072 Analysis of Cocke-Younger-Kasami and Earley Algorithms on Probabilistic Context-Free Grammar Palash Anjania1, Shrushti Gangar2, Krina Bhimani3, Lynette D’mello4 1,2,3Student, Dept. of Computer Engineering, Dwarkadas J. Sanghvi College, Maharashtra India 4Lynette D’Mello, Professor, Dept. of Computer Engineering, Dwarkadas J. Sanghvi College, Maharashtra India ---------------------------------------------------------------------***---------------------------------------------------------------------- Abstract - Programming parsers are generally based on 2. LITERATURE REVIEW context-free grammar. The study of such grammars are of great importance around the world, out of which the CYK 2.1. CYK Algorithm and the Earley are the well-known algorithms. In this paper, we have done a comparative study on the above 2.1.1 Introduction: Cocke-Younger-Kasami algorithm two algorithms. We applied these algorithms on also known CYK or CKY algorithm is a membership probabilistic context-free grammar (PCFG) and tried to algorithm which works only on context-free grammar in analyses their results and obtained their time Chomsky Normal form (CNF). It is a Bottom-Up Dynamic complexities. The results obtained show that the Earley programming approach and is more data driven. algorithm have proved to be better than the CYK Probabilistic CYK recovers the most probable parse algorithm. given the probabilities of all productions and used to decide whether the string belongs to the grammar or Key Words: Cocke-Younger-Kasami algorithm, Earley not. In Context-free Grammar the right-hand side of each algorithm, Probabilistic Context-free grammar, production can have either one terminal or two non- terminals.
    [Show full text]
  • Syntactic Parsing: Introduction, CYK Algorithm
    Introduction Syntax Context-Free Grammars CYK Algorithm Syntactic Parsing: Introduction, CYK Algorithm M. Rajman & J.-C. Chappelier Laboratoire d’Intelligence Artificielle Faculté I&C ©EPFL M. Rajman & J.-C. Chappelier Syntactic parsing: Introduction & CYK Algorithm – 1 / 47 Introduction Syntax Objectives of this lecture Context-Free Grammars CYK Algorithm ¯ Introduce syntactic level of NLP ¯ Present its two components: formal grammars and parsing algorithms Contents: I Introduction I Formal Grammars I Context-Free Grammars I CYK Algorithm ©EPFL M. Rajman & J.-C. Chappelier Syntactic parsing: Introduction & CYK Algorithm – 2 / 47 Introduction Syntax Syntactic level Syntactic level and Parsing Syntactic acceptability Formalisms Context-Free Analysis of the sentence structure Grammars CYK Algorithm i.e. "grammatical" analysis (in the linguistic sense) Automatic natural language processing requires formal grammars (ressource) and parsing algorithms Two separated/complementary aspects: procedural declarative generic algorithms data parsing algorithm formal grammar ©EPFL M. Rajman & J.-C. Chappelier Syntactic parsing: Introduction & CYK Algorithm – 3 / 47 Introduction Syntax Parsing Syntactic level and Parsing Syntactic acceptability Formalisms Context-Free Grammars Parsing can be seen as: CYK Algorithm I RECOGNIZING a sequence of words ¯ Is a given sentence correct or not? or as I ANALYZING a sequence of words ¯ For a syntactically correct sentence, give the set of all its possible interpretations (i.e. associated structures). (Returns the
    [Show full text]
  • Parallel Parsing of Context-Free Grammars
    Master Thesis Computer science Thesis no: MCS-2011-28 December 2011 Parallel parsing of context-free grammars Piotr Skrzypczak School of Computing Blekinge Institute of Technology SE-371 79 Karlskrona Sweden This thesis is submitted to the School of Computing at Blekinge Institute of Technology in partial fulfillment of the requirements for the degree of Master of Computer Science. The thesis is equivalent to 20 weeks of full time studies. Contact Information: Author(s): Piotr Skrzypczak 871216-P317 E-mail: [email protected] University advisor(s): Olgierd Unold, PhD, DSc Faculty of Electronics, Wroclaw University of Technology, Poland Bengt Aspvall, PhD School of Computing School of Computing Blekinge Institute of Technology Internet : www.bth.se/com SE-371 79 Karlskrona Phone : +46 455 38 50 00 Sweden Fax : +46 455 38 50 57 ABSTRACT During the last decade increasing interest in parallel programming can be observed. It is caused by a tendency of developing microprocessors as a multicore units, that can perform instructions simultaneously. Pop- ular and widely used example of such platform is a graphic processing unit (GPU). Its ability to perform calculations simpultaneously is being investigated as a way for improving performance of the complex algorithms. Therefore, GPU’s are now having the architectures that allows to use its computional power by programmers and software de- velopers in the same way as CPU. One of these architectures is CUDA platform, developed by nVidia. Aim of this thesis is to implement the parallel CYK algorithm, which is one of the most popular parsing algorithms, for CUDA platform, that will gain a significant speed-up in comparison with the sequential CYK algorithm.
    [Show full text]
  • Parsing of Context-Free Grammars
    Parsing of Context-Free Grammars Bernd Kiefer {Bernd.Kiefer}@dfki.de Deutsches Forschungszentrum f¨ur k¨unstliche Intelligenz Introduction to CL - Context-Free Grammars – p.1/32 Limits of Regular Expressions Assignment: Write a regular expression for fully bracketed arithmetic expressions! Answer: ? Introduction to CL - Context-Free Grammars – p.2/32 Limits of Regular Expressions Assignment: Write a regular expression for fully bracketed arithmetic expressions! Answer: This is not possible! Regular expressions can only count finite amounts of brackets Introduction to CL - Context-Free Grammars – p.2/32 Limits of Regular Expressions Assignment: Write a regular expression for fully bracketed arithmetic expressions! Answer: This is not possible! Regular expressions can only count finite amounts of brackets We need a more powerful formal device: context-free grammars Introduction to CL - Context-Free Grammars – p.2/32 Limits of Regular Expressions Assignment: Write a regular expression for fully bracketed arithmetic expressions! Answer: This is not possible! Regular expressions can only count finite amounts of brackets We need a more powerful formal device: context-free grammars Context-free grammars provide a (finite) inventory of named brackets All regular languages are also context-free, i.e.: for every regular expression, there is a context-free grammar that accepts / derives the same language Introduction to CL - Context-Free Grammars – p.2/32 Context-Free Grammars A context-free grammar (CFG) consists of: The set of terminal symbols Σ =
    [Show full text]
  • An Efficient Context-Free Parsing Algorithm for Natural Languages1
    An Efficient Context-free Parsing Algorithm For Natural Languages1 Masaru Tomita Computer Science Department Carnegie-Mellon University Pittsburgh, PA 15213 Abstract because those algorithms are not tuned for any particular subset of context-free grammars, and must be able to handle all difficult This paper introduces an efficient context-free parsing phenomena in context-free grammars. In other words, they do algorithm and emphasizes its practical value in natural not take advantage of inherent features of the programming language processing. The algorithm can be viewed as an language. Intuitively speaking, algorithms in this group are extended LR parsing algorithm which embodies the concept efficient for "hard" grammars by sacrificing efficiency on "easy" of a "graph-structured stack." Unlike the standard LR, the grammars. algorithm is capable of handling arbitrary non cyclic context-free grammars including ambiguous grammars, No parsing algorithm has been designed that takes advantage while most of the LR parsing efficiency is preserved. The of inherent features of natural languages. Because natural algorithm seems more efficient than any existing algorithms languages include slightly more difficult phenomena than including the Cocke Younger Kasami algorithm and Earley's programming languages, we cannot simply use the first group of algorithm, as far as practical natural language parsing is algorithms for natural languages. Natural languages are a little concerned, due to utilization of LR parsing tables. The "harder" than programming languages, but they are still much algorithm is an all-path parsing algorithm; it produces all "easier" than general context-free languages As we have seen possible parse trees (a parse forest) in an efficient above, we have context-free parsing algorithms at two extremes.
    [Show full text]
  • 14.5 Supplemental: Context Free Grammars: the CYK Algorithm
    Algorithms & Models of Computation CS/ECE 374, Fall 2020 14.5 Supplemental: Context free grammars: The CYK Algorithm FLNAME:14.5.0.0 ZZZ:14.5.0.0 Supplemental: Context free grammars: The CYK Algorithm 69 / 83 Algorithms & Models of Computation CS/ECE 374, Fall 2020 14.5.1 CYK: Problem statement, basic idea, and an example FLNAME:14.5.1.0 ZZZ:14.5.1.0 CYK: Problem statement, basic idea, and an example 70 / 83 Parsing We saw regular languages and context free languages. Most programming languages are specified via context-free grammars. Why? CFLs are sufficiently expressive to support what is needed. At the same time one can “efficiently” solve the parsing problem: given a string/program w, is it a valid program according to the CFG specification of the programming language? 71 / 83 CFG specification for C 72 / 83 Algorithmic Problem Given a CFG G = (V ; T; P; S) and a string w 2 T ∗, is w 2 L(G)? That is, does S derive w? Equivalently, is there a parse tree for w? Simplifying assumption: G is in Chomsky Normal Form (CNF) Productions are all of the form A ! BC or A ! a. If 2 L then S ! is also allowed. (This is the only place in the grammar that has an ".) Every CFG G can be converted into CNF form via an efficient algorithm Advantage: parse tree of constant degree. 73 / 83 Algorithmic Problem Given a CFG G = (V ; T; P; S) and a string w 2 T ∗, is w 2 L(G)? That is, does S derive w? Equivalently, is there a parse tree for w? Simplifying assumption: G is in Chomsky Normal Form (CNF) Productions are all of the form A ! BC or A ! a.
    [Show full text]