A View of the Origins and Development of Prolog
Total Page:16
File Type:pdf, Size:1020Kb
ARTICLES A VIEW OF THE ORIGINS AND DEVELOPMENT OF PROLOG Dealing with failure is easy: Work hard to improve. Success is also easy to handle: You’ve solved the wrong problem. Work hard to improve. (UNIX “fortune” message aptly describing Prolog’s sequential search mechanism in finding all solutions to ,a query) JACQUES COHEN The birth of logic programming can be viewed as the tives of the significant work done in the described confluence of two different research endeavors: one in areas. This review contrasts and complements these artificial or natural language processing, and the other two references by providing the background and moti- in automatic theorem proving. It is fair to say that both vation that led to the development of Prolog as a pro- these endeavors contributed to the genesis of Prolog. gramming language. Alain Colmerauer’s contribution stemmed mainly from The underlying thesis is that even seemingly abstract his interest in language processing, whereas Robert Ko- and original computer languages are discovered rather walski’s originated in his expertise in logic and theorem than invented. This by no means diminishes t:he formi- proving. (See [26] and the following article.) dable feat involved in discovering a language. It is This paper explores the origins of Prolog based on tempting to paraphrase the path to discovery in terms views rising mainly from the language processing per- of Prolog’s own search mechanism: One has to combine spective. With this intent we first describe the related the foresight needed to avoid blind alleys with the aes- research efforts and their significant computer litera- thetic sense required to achieve the simplest and most ture in the mid-1960s. We then show that those exist- elegant solution to a given problem. In our view the ing circumstances would very naturally lead to the de- various research topics studied by Colmerauer and his velopment of a language like Prolog. colleagues, including myself, (almost) determi.nistically In this paper I present a review of the origins and led to the development of Prolog. development of Prolog based on a long-term associa- tion, both academic and personal, with Colmerauer, the AN EARLY INVOLVEMENT WITH SYNTAX computer scientist who led the Marseilles team in help- ANALYSIS ing to develop that language. Both Colmerauer and I started doing research on com- A description of the evolution of logic programming pilers in the fall of 1963. Our research group at the presented by Robinson covers over a century of events Institute of Applied Mathematics, attached to the Uni- stemming from the work of Frege [37]. Loveland’s re- versity of Grenoble, was led by Louis Bolliet. [t was an view of the related area of automated theorem proving exciting period for French informatics. First, i.here was spans a quarter of a century of developments in that a national pride involved in building up a computer field [29]. industry. Although not entirely successful in its practi- Both Robinson’s and Loveland’s papers contain narra- cal performance, the Bull Gamma 60 computer was rec- ognized as having a novel architecture and showed the This work was partly supported by the National Science Foundation under talent and promise of its hardware designers. Second, Grant DCR 85-00861. there was an effort to decentralize research from Paris by providing additional funds to the regional universi- 0 1988 ACM 0001.0782/88/0100-0026 $1.50 ties. The University of Grenoble was at the time one of 26 Communications of the ACM January 1988 Volume 31 Number 1 Articles the most active in software development and in numer- l How could one reduce the degree of nondeterminism ical analysis; considerable funds were made available necessary for parsing? to Bolliet’s group. l Could Dijkstra’s empirically derived weights be de- One of the projects undertaken by the group was the termined formally for various classes of grammars? development of an Algol 60 compiler for an IBM 7044, Two remarkable papers addressed these questions and considered a fairly large mainframe at the time. J.C. were avidly read by members of the group. The first, by Boussard was responsible for that project, and all mem- Griffiths and Petrick, described an attempt to quantify bers of the group collaborated in testing the compiler. backtracking in parsing [18]. Their approach was to se- We familiarized ourselves with the Algol 60 Report [32] lect a two-stack nondeterministic Turing machine and and with the existing compiling techniques. Several of use its instructions to write various parsers for different us marveled at the pioneering and highly intuitional grammars. Nondeterminism could be controlled by us- approach of Rutishauser in the multiple pass compila- ing a selectivity matrix that allowed the parser to avoid tion of arithmetic expressions (see [l]). The next major certain blind alleys. By simulating the Turing machine work read by most of us was that of Dijkstra [14], in on a computer, the authors were able to measure the which a stack and empirically derived weights were relative efficiencies of the various parsers. used to perform a single pass compilation of Algol 60 The second paper, by Floyd [15], described automatic programs. Bauer, Samelson, and Paul had also done means for generating a matrix from a given grammar. work along similar lines, this time trying to establish a This matrix, called a precedence matrix, was then used relationship between a given BNF grammar and the by the parser to perform a (deterministic) syntactic weights used by Dijkstra in his empirical approach [33, analysis of input strings. Floyd also showed that infor- 401. However, in our view it was Floyd [15] who first mation contained in the matrix could, in certain cases, succeeded in automatically determining that relation- automatically yield the weights that had been empiri- ship for certain classes of grammars. cally determined by Dijkstra. Before analyzing the effect of Floyd’s work on the The precedence matrix could always be generated members of our group, I would like to digress briefly from grammars not containing two adjacent nontermin- to describe a few related papers that raise the issue of als in the right-hand side of a rule. It was also known determinism versus nondeterminism, which in turn is that any BNF grammar could be “massaged” into an- central to the theme of this article. Brooker and Morris other one whose rules had that special type of right- in England and Irons in the United States had by this hand sides. Determinism could only be attained if the time suggested innovative approaches to compilation generated matrix contained single entries. One could called syntax-directed translations. Brooker and Morris imagine a Floyd-type nondeterministic parser that, showed how recursive procedures obtained automati- when confronted with multiple entries in the matrix, cally from the grammar rules could parse a string in the would successively try each one of them and backtrack language generated by the grammar [3, 41. Actions were whenever a blind alley was reached. then triggered whenever certain syntactic constructs Nevertheless, for compiler writing purposes, nonde- were encountered while parsing. terminism was to be avoided, and it became desirable Iron’s compiler also used a parser defined by recur- to extend Floyd’s work to other classes of grammars. sive procedures that, in contrast to Brooker’s, was Wirth and Weber’s paper [45] eliminated the restric- guided by data representing the grammar rules [Zl]. A tions imposed by Floyd as to the type of right-hand notable characteristic of the parsers proposed by these sides of rules. Essentially, Floyd’s precedence matrix authors is that they could operate in a nondeterministic was constructed only for the elements of the terminal manner by trying to apply a given grammar rule and, in vocabulary. Wirth and Weber extended the matrix con- struction and parsing to cover nonterminals as well as terminals. That, however, introduced an asymmetry It was an exciting period for French that was not aesthetically pleasing since parsing had to iyformatics. there was a national pride proceed sequentially from left to right. involved in building up a computer Colmerauer’s project was to write an error detection and recovery program for Algol 60. After studying the industry. Griffiths-Petrick and Floyd papers, he first thought of means to generalize Floyd’s ideas in order to make them applicable to wider classes of grammars. In his case of failure, backtrack to try another rule. The non- 1967 dissertation on total precedence relations [7], deterministic parsers were more general (i.e., they Colmerauer restored the parsing symmetry by allowing could process other classes of grammars), but less effi- nonterminals to appear as elements of a (pseudo) input cient than their deterministic counterparts. string behaving as a stack. The similarity to Griffiths With these previous works available, the Grenoble and Petrick’s two-stack Turing machine then becomes compiler’s group began to have a clearer idea of the obvious. type of research that could yield significant results. Finally, it should be mentioned that, although Among the pertinent questions were, Knuth’s work on LR (k) grammars was known to us at January 1988 Volume 31 Number 1 Communications of the ACM 27 Articles the time, his mainly theoretical emphasis offered little Colmerauer’s involvement with W-grammars repre- hope of usage in actual compilers [ZZ]. (Later devel- sented another step (perhaps unconscious at the time] opments, however, proved this was not the case for toward designing the future language. In fact, Colmer- small k.) auer implemented an analyzer for strings generated by W-grammars, as well as a sentence generator operating NONDETERMINISTIC ALGORITHMS AND on given grammar rules.