Logic Programming and Logic Grammars with Binarization and First-order Continuations Paul Tarau1 and Veronica Dahl2 1 Universit?e de Moncton D?epartement d'Informatique Moncton , N.B. Canada E1A 3E9 , tarau@info.umoncton.ca 2 Logic Programming Group Department of Computing Sciences Simon Fraser University Burnaby , B.C. Canada V5A 1S6 veronica@cs.sfu.ca Abstract . Continuation passing binarization and specialization of the WAM to binary logic programs have been proven practical implementation techniques in the BinProlog system . In this paper we investigate the additional benefits of having first order continuations at source level . We devise a convenient way to manipulate them by introducing multipleheaded clauses which give direct access to continuations at source-level . We discuss the connections with various logic grammars , give examples of typical problem solving tasks and show how looking at the future of computation can improve expressiveness and describe complex control mechanisms without leaving the framework of binary definite programs . 1 Introduction From its very inception , logic programming has cross-fertilized with computational linguistics in very productive ways . Indeed , logic programming itself grew from the automatic deduction needs of a question-answering system in French -LSB- 7 -RSB- . Over the years we have seen other interesting instances of this close-relatedness . The idea of continuations , developed in the field of denotational semantics -LSB- 22 -RSB- and functional programming -LSB- 27 , 26 -RSB- has found its way into programming applications , and has in particular been useful recently in logic programming . In this article we continue this tradition by adapting to logic programming with continuations some of the techniques that were developed in logic grammars for computational linguistic applications . In particular , logic grammars have been augmented by allowing extra symbols and meta-symbols in the left hand sides of rules -LSB- 6 , 17 , 9 -RSB- . Such extensions allow for straightforward expressions of contextual information , in terms of which many interesting linguistic phenomena have been described . We show that such techniques can be efficiently transfered to continuation passing binary programs , that their addition motivates an interesting style of programming for applications other than linguistic ones , and that introducing continuations in logic grammars with multiple left-hand-side symbols motivates in turn novel styles of bottom-up and mixed parsing , while increasing efficiency . 2 Motivation Several attempts to enhance the expressiveness of logic programming have been made over the years . These efforts range from simply providing handy notational variants , as in DCGs , to implementing sophisticated new frameworks , such as HiLog -LSB- 5 , 29 -RSB- . In > = Prolog for instance -LSB- 14 , 15 -RSB- there is a nice facility , that of scoping of clauses , which is provided by the > = Prolog incarnation of the intuitionistic rule for implication introduction : ? ; ? ; P ` C ? ; P ` ? -RRB- C -RRB- R Example 1 For instance , in the > = Prolog program 3 : insert X Xs Ys : - paste X = > ins Xs Ys . ins Ys -LSB- X | Ys -RSB- : - paste X. ins -LSB- Y | Ys -RSB- -LSB- Y | Zs -RSB- : - ins Ys Zs . used to nondeterministically insert an element in a list , the unit clause paste X is available only within the scope of the derivation for ins . With respect to the corresponding Prolog program we are working with a simpler formulation in which the element to be inserted does not have to percolate as dead weight throughout each step of the computation , only to be used in the very last step . We instead clearly isolate it in a global-value manner , within a unit clause which will only be consulted when needed , and which will disappear afterwards . Now , let us imagine we are given the ability to write part of a proof state context , i.e. , to indicate in a rule 's left-hand side not only the predicate which should match a goal atom to be replaced by the rule 's body , but also which other goal atom -LRB- s -RRB- should surround the targeted one in order for the rule to be applicable . Example 2 Given this , we could write a program for insert which strikingly resembles the > = Prolog program given above : 3 where for instance insert X Xs Ys means insert -LRB- X , Xs , Ys -RRB- in curried notation insert -LRB- X , Xs , Ys -RRB- : - ins -LRB- Xs , Ys -RRB- , paste -LRB- X -RRB- . ins -LRB- Ys , -LSB- X | Ys -RSB- -RRB- , paste -LRB- X -RRB- . ins -LRB- -LSB- Y | Ys -RSB- , -LSB- Y | Zs -RSB- -RRB- : - ins -LRB- Ys , Zs -RRB- . Note that the element to be inserted is not passed to the recursive clause of the predicate ins/2 -LRB- which becomes therefore simpler -RRB- , while the unit clause of the predicate ins/2 will communicate directly with insert/3 which will directly ` paste ' the appropriate argument in the continuation . In this formulation , the element to be inserted is first given as right-hand side context of the simpler predicate ins/2 , and this predicate 's first clause consults the context paste -LRB- X -RRB- only when it is time to place it within the output list , i.e. when the fact ins -LRB- Ys , -LSB- X | Ys -RSB- -RRB- , paste -LRB- X -RRB- is reached . Thus for this example , we can obtain the expressive power of > = Prolog without having to resort to an entirely new framework . As we shall see in the next sections , we can simply use any Prolog system combined with a simple transformer to binary programs -LSB- 24 -RSB- . 3 Multiple Head Clauses in Continuation Passing Binary Programs We will start by reviewing the program transformation that allows compilation of logic programs towards a simplified WAM specialized for the execution of binary logic programs . We refer the reader to -LSB- 24 -RSB- for the original definition of this transformation . 3.1 The binarization transformation Binary clauses have only one atom in the body -LRB- except for some inline ` builtin ' operations like arithmetics -RRB- and therefore they need no ` return ' after a call . A transformation introduced in -LSB- 24 -RSB- allows to faithfully represent logic programs with operationally equivalent binary programs . To keep things simple we will describe our transformations in the case of definite programs . First , we need to modify the well-known description of SLD - resolution -LRB- see -LSB- 11 -RSB- -RRB- to be closer to Prolog 's operational semantics . We will follow here the notations of -LSB- 25 -RSB- . Let us define the composition operator ? that combines clauses by unfolding the leftmost body-goal of the first argument . Definition 1 Let A0 : - A1 , A2 , : : : , An and B0 : - B1 , : : : , Bm be two clauses -LRB- suppose n > ; m > = -RRB- . We define -LRB- A0 : - A1 , A2 , : : : , An -RRB- ? -LRB- B0 : - B1 , : : : , Bm -RRB- = -LRB- A0 : - B1 , : : : , Bm , A2 , : : : , An -RRB- ? with ? = mgu -LRB- A1 , B0 -RRB- . If the atoms A1 and B0 do not unify , the result of the composition is denoted as ? . Furthermore , as usual , we consider A0 : - true , A2 , : : : , An to be equivalent to A0 : - A2 , : : : , An , and for any clause C , ? ? C = C ? ? = ? . We assume that at least one operand has been renamed to a variant with fresh variables . Let us call this Prolog-like inference rule LF-SLD resolution -LRB- LF for ` leftfirst ' -RRB- . Remark that by working on the program P obtained from P by replacing each clause with the set of clauses obtained by all possible permutations of atoms occurring in the clause 's body every SLD-derivation on P can be mapped to an LF-SLD derivation on P . Before defining the binarization transformation , we describe two auxiliary transformations . The first transformation converts facts into rules by giving them the atom true as body . E.g. , the fact p is transformed into the rule p : - true . The second transformation , inspired by -LSB- 28 -RSB- , eliminates the metavariables by wrapping them in a call/1 goal . E.g. , the rule and -LRB- X , Y -RRB- : - X , Y is transformed into and -LRB- X , Y -RRB- : - call -LRB- X -RRB- , call -LRB- Y -RRB- . The transformation of -LSB- 24 -RSB- -LRB- binarization -RRB- adds continuations as extra arguments of atoms in a way that preserves also first argument indexing . Definition 2 Let P be a definite program and Cont a new variable . Let T and E = p -LRB- T1 ; : : : ; Tn -RRB- be two expressions .4 We denote by -LRB- E ; T -RRB- the expression p -LRB- T1 ; : : : ; Tn ; T -RRB- . Starting with the clause -LRB- C -RRB- A : ? B1 ; B2 ; : : : ; Bn : we construct the clause -LRB- C ' -RRB- -LRB- A ; Cont -RRB- : ? -LRB- B1 ; -LRB- B2 ; : : : ; -LRB- Bn ; Cont -RRB- -RRB- -RRB- : The set P of all clauses C ' obtained from the clauses of P is called the binarization of P. Example 3 The following example shows the result of this transformation on the well-known ` naive reverse ' program : app -LRB- -LSB- -RSB- , Ys , Ys , Cont -RRB- : - true -LRB- Cont -RRB- . app -LRB- -LSB- A | Xs -RSB- , Ys , -LSB- A | Zs -RSB- , Cont -RRB- : - app -LRB- Xs , Ys , Zs , Cont -RRB- . nrev -LRB- -LSB- -RSB- , -LSB- -RSB- , Cont -RRB- : - true -LRB- Cont -RRB- . nrev -LRB- -LSB- X | Xs -RSB- , Zs , Cont -RRB- : - nrev -LRB- Xs , Ys , app -LRB- Ys , -LSB- X -RSB- , Zs , Cont -RRB- -RRB- . These transformations preserve a strong operational equivalence with the original program with respect to the LF-SLD resolution rule which is reified in the syntactical structure of the resulting program . Theorem 1 -LRB- -LSB- 25 -RSB- -RRB- Each resolution step of an LF-SLD derivation on a definite program P can be mapped to an SLD-resolution step of the binarized program P . Let G be an atomic goal and G0 = -LRB- G ; true -RRB- . Then , computed answers obtained querying P with G are the same as those obtained by querying P ' with G ' . 4 Atom or term . Notice that the equivalence between the binary version and the original program can also be explained in terms of fold/unfold transformations as suggested by -LSB- 18 -RSB- . Clearly , continuations become explicit in the binary version of the program . We will devise a technique to access and manipulate them in an intuitive way , by modifying BinProlog 's binarization preprocessor . 3.2 Modifying the binarization preprocessor for multi-head clauses The main difficulty comes from the fact that trying to directly access the continuation from ` inside the continuation ' creates a cyclic term . We have overcome this in the past by copying the continuation in BinProlog 's blackboard -LRB- a permanent data area -RRB- but this operation was very expensive . The basic idea of the approach in this paper is inspired by ` pushback lists ' originally present in -LSB- 6 -RSB- and other techniques used in logic grammars to simulate movement of constituents -LSB- 9 -RSB- . We will allow a multiple head notation as in : a , b , c :-d , e. intended to give , via binarization : a -LRB- b -LRB- c -LRB- A -RRB- -RRB- -RRB- : - d -LRB- e -LRB- A -RRB- -RRB- This suggests the following : Definition 3 A multiheaded definite clause is a clause of the form : A1 ; A2 ; : : : ; Am : ? B1 ; B2 ; : : : ; Bn : A multiheaded definite program is a set of multiheaded definite clauses . Logically speaking , ' , ' / 2 in A1 ; A2 ; : : : ; Am : ? B1 ; B2 ; : : : ; Bn is interpreted as conjunction on both sides . The reader familiar with grammar theory will notice -LRB- as suggested by -LSB- 13 -RSB- -RRB- that generalizing from definite to multi-headed definite programs is similar to going from context-free grammars to context-dependent grammars . The binarization of the head will be extended in a way similar to that of the binarization of the right side of a clause . Definition 4 Let P be a multiheaded definite program and Cont a new variable . Starting with the multiheaded clause -LRB- C -RRB- A1 ; A2 : : : ; Am : ? B1 ; B2 ; : : : ; Bn : we construct the clause -LRB- C ' -RRB- -LRB- A1 ; -LRB- A2 ; : : : ; -LRB- Am ; Cont -RRB- -RRB- -RRB- : ? -LRB- B1 ; -LRB- B2 ; : : : ; -LRB- Bn ; Cont -RRB- -RRB- -RRB- : Note that after this transformation the binarized head will be able to match the initial segment of the current implicit goal stack of BinProlog embedded in the continuation , i.e. to look into the immediate future of the computation . Somewhat more difficult is to implement ` meta-variables ' in the left side . In the case of a goal like : a , Next : - write -LRB- Next -RRB- , nl , b -LRB- Next -RRB- . we need a more complex binary form : a -LRB- A -RRB- : - strip_cont -LRB- A , B , C , write -LRB- B , nl -LRB- b -LRB- B , C -RRB- -RRB- -RRB- -RRB- . where strip_cont -LRB- GoalAndCont , Goal , Cont -RRB- is needed to undo the binarization and give the illusion of getting the goal Next at source level by unification with a metavariable on the left side of the clause a/1 . Notice that the semantics of the continuation manipulation predicate strip_cont / 3 is essentially first order , as we can think of strip_cont simply as being defined by a set of clauses like : ... . strip_cont -LRB- f -LRB- X1 , ... , Xn , C -RRB- , f -LRB- X1 , ... , Xn -RRB- , C -RRB- . ... . for every functor f occuring in the program . The full code of the preprocessor that handles multiples-headed clauses is given in Appendix A. 4 Programming with Continuations in Multiple-headed clauses The first question that comes to mind is how well our transformation technique performs compared with handwritten programs . Example 4 The following program is a continuation based version of nrev/2 . app -LRB- Xs , Ys , Zs -RRB- : - app_args -LRB- Xs , Zs -RRB- , paste -LRB- Ys -RRB- . app_args -LRB- -LSB- -RSB- , -LSB- X -RSB- -RRB- , paste -LRB- X -RRB- . app_args -LRB- -LSB- A | Xs -RSB- , -LSB- A | Zs -RSB- -RRB- : - app_args -LRB- Xs , Zs -RRB- . nrev -LRB- -LSB- -RSB- , -LSB- -RSB- -RRB- . nrev -LRB- -LSB- X | Xs -RSB- , R -RRB- : - nrev1 -LRB- Xs , R -RRB- , paste -LRB- X -RRB- . nrev1 -LRB- Xs , R -RRB- : - nrev -LRB- Xs , T -RRB- , app_args -LRB- T , R -RRB- . which shows no loss in speed compared to the original program -LRB- 530 KLIPS with BinProlog 2.20 on a Sparcstation 10-40 -RRB- . One of Miller 's motivating examples for intuitionistic implication in > = Prolog 5 -LSB- 14 -RSB- , is the reverse predicate with intuitionistic implication . Example 5 By using our multi-headed clauses we can write a such a reverse predicate as follows : reverse -LRB- Xs , Ys -RRB- : - rev -LRB- Xs , -LSB- -RSB- -RRB- , result -LRB- Ys -RRB- . rev -LRB- -LSB- -RSB- , Ys -RRB- , result -LRB- Ys -RRB- . rev -LRB- -LSB- X | Xs -RSB- , Ys -RRB- : - rev -LRB- Xs , -LSB- X | Ys -RSB- -RRB- . which gives after binarization : reverse -LRB- Xs , Ys , Cont -RRB- : - rev -LRB- Xs , -LSB- -RSB- , result -LRB- Ys , Cont -RRB- -RRB- . rev -LRB- -LSB- -RSB- , Ys , result -LRB- Ys , Cont -RRB- -RRB- : - true -LRB- Cont -RRB- . rev -LRB- -LSB- X | Xs -RSB- , Ys , Cont -RRB- : - rev -LRB- Xs , -LSB- X | Ys -RSB- , Cont -RRB- . with a suitable definition for true/1 as : true -LRB- C -RRB- : - C. and with a clause like reverse -LRB- Xs , Ys -RRB- : - reverse -LRB- Xs , Ys , true -RRB- . Notice that such definitions are ` virtual ' -LRB- i.e. supplied by generic WAM-level operations -RRB- in BinProlog , for space and efficiency reasons -LSB- 23 -RSB- . By replacing true -LRB- C -RRB- : - C an appropriate set of clauses where C =p -LRB- X1 , ... , Xn -RRB- for every head of clause p/n occurring in the program , we obtain a definite binary program which accurately describes the operational semantics of the original multi-headed program . Although the existence of such a translation is expected -LRB- as binary definite programs are Turing-equivalent -RRB- its simple syntactic nature rehabilitates the idea of using a translation semantics as an ` internal ' means to describe the semantics of multi-headed logic programs , despite the fact that it fixes an implementation as the meaning of a programming construct . The availability of such a programming style in the Horn subset of Prolog is also of practical importance as classical Prolog is still about 5-10 times faster than , for instance , the fastest known > = Prolog implementation -LSB- 4 -RSB- . Example 6 The following program implements a map predicate with a Hilogstyle -LRB- see -LSB- 5 -RSB- -RRB- syntax : 5 which is , by the way , a motivating example also for Andreoli and Pareschi 's Linear Objects , -LSB- 2 -RSB- cmap -LRB- F -RRB- , i -LRB- -LSB- -RSB- -RRB- , o -LRB- -LSB- -RSB- -RRB- . cmap -LRB- F -RRB- , i -LRB- -LSB- X | Xs -RSB- -RRB- , o -LRB- -LSB- Y | Ys -RSB- -RRB- : - G = . . -LSB- F , X , Y -RSB- , G , cmap -LRB- F -RRB- , i -LRB- Xs -RRB- , o -LRB- Ys -RRB- . inc10 -LRB- X , Y -RRB- : - Y is X +10 . test : - cmap -LRB- inc10 -RRB- , i -LRB- -LSB- 1,2,3,4,5,6 -RSB- -RRB- , o -LRB- Xs -RRB- , write -LRB- Xs -RRB- , nl . Some interesting optimization opportunities by program transformation can be obtained by using multiple-headed clauses , as can be seen in the following example of elimination of existential variables -LRB- this technique has been pioneered by Proietti and Pettorossi , in a fold/unfold based framework , -LSB- 19 -RSB- -RRB- . Example 7 Given the program : r -LRB- X , Y -RRB- :-p -LRB- X , N -RRB- , q -LRB- N , Y -RRB- . p -LRB- a ,1 -RRB- . q -LRB- 1,10 -RRB- . p -LRB- b ,2 -RRB- . q -LRB- 2,11 -RRB- . we can rewrite it as : r -LRB- X , Y -RRB- :-p -LRB- X -RRB- , result -LRB- Y -RRB- . p -LRB- a -RRB- : - q -LRB- 1 -RRB- . p -LRB- b -RRB- : - q -LRB- 2 -RRB- . q -LRB- 1 -RRB- , result -LRB- 10 -RRB- . q -LRB- 2 -RRB- , result -LRB- 11 -RRB- . which avoid passing unnecessary information by directly unifying the 2 occurrences of result -LRB- _ -RRB- . Example 8 Multi-headed clauses can be used to ensure direct communication with the leafs of a tree -LRB- represented simply as a Prolog term -RRB- . frontier -LRB- T , X -RRB- : - leaf_var -LRB- T -RRB- , result -LRB- X -RRB- . leaf_var -LRB- X -RRB- , result -LRB- X -RRB- : - var -LRB- X -RRB- . leaf_var -LRB- T -RRB- : - compound -LRB- T -RRB- , T = . . -LSB- _ | Xs -RSB- , member -LRB- X , Xs -RRB- , leaf_var -LRB- X -RRB- . where ? - frontier -LRB- X -RRB- returns non-deterministically all the variables in a term seen as a -LRB- finite -RRB- tree . The example also shows that the technique scales easily to arbitrary recursive data-types , and to programs in practice beyond the domain of definite programs . As it can be seen from the previous examples , the advantage of our technique is that the programmer can follow an intuitive , grammar-like semantics when dealing with continuations and that ` predictability ' of the fact that the continuation will be at the right place at the right time is straightforward . The next section will show some special cases where full access to continuations is more convenient . 5 Multiple headed clauses vs. full-blown continuations BinProlog 2.20 supports direct manipulation of binary clauses denoted Head : : - Body . They give full power to the knowledgeable programmer on the future of the computation . Note that such a facility is not available in conventional WAM - based systems where continuations are not first-order objects . Example 9 We can use them to write programs like : member_cont -LRB- X , Cont -RRB- : : - strip_cont -LRB- Cont , X , NewCont , true -LRB- NewCont -RRB- -RRB- . member_cont -LRB- X , Cont -RRB- : : - strip_cont -LRB- Cont , _ , NewCont , member_cont -LRB- X , NewCont -RRB- -RRB- . test -LRB- X -RRB- : - member_cont -LRB- X -RRB- , a , b , c . A query like ? - test -LRB- X -RRB- . will return X = a ; X = b ; X = c ; X = whatever follows from the calling point of test -LRB- X -RRB- . catch -LRB- Goal , Name , Cont -RRB- : : - lval -LRB- catch_throw , Name , Cont , call -LRB- Goal , Cont -RRB- -RRB- . throw -LRB- Name , _ -RRB- : : - lval -LRB- catch_throw , Name , Cont , nonvar -LRB- Cont , Cont -RRB- -RRB- . where lval -LRB- K1 , K2 , Val -RRB- is a BinProlog primitive which unifies Val with a backtrackable global logical variable accessed by hashing on two -LRB- constant or variable -RRB- keys K1 , K2 . Example 10 This allows for instance to avoid execution of the infinite loop from inside the predicate b/1 . loop : - loop . c -LRB- X -RRB- : - b -LRB- X -RRB- , loop . b -LRB- hello -RRB- : - throw -LRB- here -RRB- . b -LRB- bye -RRB- . go : - catch -LRB- c -LRB- X -RRB- , here -RRB- , write -LRB- X -RRB- , nl . Notice that due to our translation semantics this program still has a first order reading and that BinProlog 's lval/3 is not essential as it can be emulated by an extra argument passed to all predicates . Although implementation of catch and throw requires full-blown continuations , we can see that at user level , the multi-headed clause notation is enough . 6 Continuation Grammars By allowing us to see the right context of a given grammar symbol , continuations can make logic grammars both more efficient and simpler , as well as provide several sophisticated capabilities within a simple framework . We next discuss some of these capabilities . 6.1 Parsing strategy versatility Changing parsing strategies is usually deemed to require a different parser . We now discuss how we can effect these changes with no more apparatus than continuation grammars . Take for instance the noun phrase `` Peter , Paul and Mary '' . We can first use a tokenizer which transforms it into the sequence Example 11 -LRB- noun -LRB- ` Peter ' -RRB- , comma , noun -LRB- ` Paul ' -RRB- , and , noun -LRB- ` Mary ' -RRB- -RRB- and then use this sequence to define the rule for list-of-names in the following continuation grammar : names -- > noun -LRB- ` Peter ' -RRB- , comma , noun -LRB- ` Paul ' -RRB- , and , noun -LRB- ` Mary ' -RRB- . noun -LRB- X -RRB- , comma -- > -LSB- X , ' , ' -RSB- . noun -LRB- X -RRB- , and , noun -LRB- Last -RRB- -- > -LSB- X , ` and ' , Last -RSB- . This is an interesting way in which to implement bottom-up parsing of recursive structures , since no recursive rules are needed , yet the parser will work on lists of names of any length . It is moreover quite efficient , there being no backtracking . It can also be used in a mixed strategy , for instance we could add the rules : verb_phrase -- > verb . verb -- > -LSB- sing -RSB- . and postulate the existence of a verb phrase following the list of nouns , which would then be parsed top-down . The modified rules follow , in which we add a marker to record that we have just parsed a noun phrase , and then we look for a verb phrase that follows it . noun -LRB- X -RRB- , comma -- > -LSB- X , ' , ' -RSB- . noun -LRB- X -RRB- , and , noun -LRB- Last -RRB- -- > -LSB- X , ` and ' , Last -RSB- , parsed_noun_phrase . parsed_noun_phrase -- > verb_phrase . DCGs allow further left-hand side symbols provided they are terminal ones -LRB- it has been shown that rules with non-leading non-terminal left hand side symbols can be replaced by a set of equivalent , conforming rules -LSB- 6 -RSB- -RRB- . However , because their implementation is based on synthesizing those extra symbols into the strings being manipulated , lookahead is simulated by creating the expectation of finding a given symbol in the future , rather than by actually finding it right away . With continuations we can implement a more restricted but more efficient version of multiple-left-hand-side symbol-accepting DCGs , which we shall call continuation grammars . It is more restricted in the sense that the context that an initial left-hand side symbol is allowed to look at is strictly its right-hand side sisters , rather than any descendants of them , but by using this immediate context right away the amount of backtracking is reduced for many interesting kinds of problems . Example 12 For comparison with the length of code , here is a non-continuation based DCG formulation of the `` list of names '' example which allows for multiple left-hand side symbols 6 names -- > start , start -LRB- C -RRB- , name , end -LRB- C -RRB- , nms , end . nms -- > -LSB- -RSB- . nms -- > start -LRB- C -RRB- , name , end -LRB- C -RRB- , nms . The next two rules are for terminalizing symbols that appear in later rules as non-leading left-hand-side symbols . end -- > -LSB- end -RSB- . start -LRB- C -RRB- -- > -LSB- start -LRB- C -RRB- -RSB- . start , -LSB- end -RSB- -- > -LSB- -RSB- start , -LSB- start -LRB- C -RRB- -RSB- -- > -LSB- -RSB- . end -LRB- and -RRB- , end -- > -LSB- , -RSB- . end -LRB- comma -RRB- , start -LRB- and -RRB- -- > -LSB- and -RSB- . end -LRB- comma -RRB- , start -LRB- comma -RRB- -- > -LSB- , -RSB- . Other possible applications are to procedures to read a word or a sentence , which typically make explicit use of a lookahead character or word , to restrictive relative clauses , whose end could be detected by looking ahead for the comma that ends them , etc. . 6.2 Relating of long-distance constituents One important application in computational linguistics is that of describing movement of constituents . For instance , a common linguistic analysis would state that the object noun phrase in `` Jack built the house '' moves to the front through relativization , as in `` the house that Jack built '' , and leaves a trace behind in the phrase structure representing the sentence . For describing movement , 6 This is a simplified version of the corresponding code fragment in -LSB- 8 -RSB- . we introduce the possibility of writing one meta-variable in the left hand side of continuation grammar rules . Then our example can be handled through a rule such as the following : relative_pronoun , X , trace -- > -LSB- that -RSB- , X . This rule accounts , for instance , for \ the house that jack built '' , \ the house that the Prime Minister built '' , \ the house that the man with the yellow hat who adopted curious George built '' , and so on . A simple grammar containing a similar rule follows , the reader might try it to derive : `` The elephant that Jill photographed smiles '' : Example 13 sentence -- > noun_phrase , verb_phrase . noun_phrase -- > proper_name . noun_phrase -- > det , noun , relative . noun_phrase -- > trace . verb_phrase -- > verb , noun_phrase . verb_phrase -- > verb . relative -- > -LSB- -RSB- . relative -- > relative_marker , sentence . relative_marker , X , trace -- > relative_pronoun , X. det -- > -LSB- the -RSB- . noun -- > -LSB- elephant -RSB- . relative_pronoun -- > -LSB- that -RSB- . proper_name -- > -LSB- ` Jill ' -RSB- . verb -- > -LSB- photographed -RSB- . verb -- > -LSB- smiles -RSB- . What is noteworthy about this example is that it shows how to use plain Prolog plus binarization to achieve the same expressive power which used to require more sophisticated grammar formalisms , such as Extraposition or Discontinuous Grammars -LSB- 17 , 9 -RSB- . 6.3 Computation viewed as parsing Continuation Grammars are useful not only for linguistic or intrinsically grammatical examples , but can also serve to simplify the description of many problems which can be formulated in terms of a grammar . Example 14 For instance , we can sort a list of numbers by viewing it as an input string to a grammar , which obtains successive intermediate strings in a parallel-like fashion until two successively obtained strings are the same : sort -LRB- Input -RRB- : - s -LRB- V , V , Input , -LSB- -RSB- -RRB- , remember -LRB- Input -RRB- . s -LRB- H , -LSB- Y , X | Z -RSB- -RRB- -- > -LSB- X , Y -RSB- , -LCB- X > Y -RCB- , ! , s -LRB- H , Z -RRB- . s -LRB- H , -LSB- X | Z -RSB- -RRB- -- > -LSB- X -RSB- , s -LRB- H , Z -RRB- . s -LRB- NewString , -LSB- -RSB- -RRB- , -LCB- remember -LRB- OldString -RRB- -RCB- -- > -LCB- decide -LRB- OldString , NewString -RRB- -RCB- . decide -LRB- Result , Result -RRB- , output -LRB- Result -RRB- . decide -LRB- OldString , NewString -RRB- : - sort -LRB- NewString -RRB- . par_sort -LRB- Input , Result -RRB- : - sort -LRB- Input -RRB- , output -LRB- Result -RRB- . The first clause initializes a difference-list as empty -LRB- both the head and tail are represented by a variable V -RRB- ; adds the two extra arguments -LRB- input string and output string -RRB- that are typically needed by the Prolog translation of the grammar rules ; and pastes a reminder of the last string obtained -LRB- initially , the input string -RRB- . The first grammar rule consumes the next two numbers from the input string if they are unordered , and calls s recursively , keeping track of their ordered version in the difference list represented by the two first arguments of s . If the next two numbers to be consumed are not ordered , or if there is only one number left , the second grammar rule consumes one number , and keeps track of it in the difference list as it recursively calls s . The third grammar rule finds no more numbers to consume , so it consults the last string remembered in order to decide whether to print the result -LRB- if the new string is no different than the last one -RRB- or to start another iteration of the algorithm on the list last obtained . The last clause returns the answer directly from the continuation . For instance , on the input string L = -LSB- 8,4,5,3 -RSB- with the goal par_sort -LRB- L , R -RRB- , we successively obtain : -LSB- 4,8,3,5 -RSB- , -LSB- 4,3,8,5 -RSB- and finally R = -LSB- 3,4,5,8 -RSB- . The above example is a variation of the odd-even-transposition parallel algorithm for sorting numbers -LSB- 1 -RSB- . A grammatical version of this algorithm has been developed in terms of parametric L-systems -LSB- 20 -RSB- , an extension of L-systems which operates on parametric words and which can be viewed as a model of parallel computation . It is interesting to note that by using continuation grammars we need no special formalisms to obtain the kind of parallel computation that is provided by more elaborate formalisms such as parametric L-systems . 7 Conclusion We have proposed the use of continuation-passing binarization both for extending logic programs to allow multiple heads , and for a fresh view of those logic grammars which allow multiple left-hand-side symbols . In both of these areas , the use of continuations has invited interesting new programming -LRB- grammar -RRB- composition techniques which we have provided examples for . Other logic programming proposals involve multiple heads , e.g. disjunctive logic programming -LSB- 12 , 21 -RSB- or contextual logic programming -LSB- 16 , 10 -RSB- . However , in these approaches the notion of alternative conclusions is paramount , whereas in our approach we instead stress the notion of contiguity that computational linguistics work has inspired . A formal characterization of this stress with respect to logic grammars has been given in -LSB- 3 -RSB- . The technique has been included as a standard feature of the BinProlog 2.20 distribution available by ftp from clement.info.umoncton.ca . Acknowledgment This research was supported by NSERC Operating grant 31-611024 , and by an NSERC Infrastructure and Equipment grant given to the Logic and Functional Programming Laboratory at SFU , in whose facilities this work was developed . We are also grateful to the Centre for Systems Science , LCCR and the Department of Computing Sciences at Simon Fraser University for the use of their facilities . Paul Tarau thanks also for support from the Canadian National Science and Engineering Research Council -LRB- Operating grant OGP0107411 -RRB- and a grant from the FESR of the Universit?e de Moncton . References 1 . S. Akl . The design and analysis of parallel algorithms . Prentice Hall , Englewood Cliffs , 1989 . 2 . J.-M . Andreoli and R. Pareschi . Linear objects : Logical processes with built-in inheritance . In D. Warren and P. Szeredi , editors , 7th Int . Conf . Logic Programming , Jerusalem , Israel , 1990 . MIT Press . 3 . J. Andrews , V. Dahl , and F. Popowich . A Relevance Logic Characterization of Static Discontinuity Grammars . Technical report , CSS/LCCR TR 91-12 , Simon Fraser University , 1991 . 4 . P. Brisset . Compilation de > = Prolog . Th?ese , Universit?e de Rennes I , 1992 . 5 . W. Chen and D. S. Warren . Compilation of predicate abstractions in higher-order logic programming . In J. Maluszy?nski and M. Wirsing , editors , Proceedings of the 3rd Int . Symposium on Programming Language Implementation and Logic Programming , PLILP91 , Passau , Germany , number 528 in Lecture Notes in Computer Science , pages 287 -LCB- 298 . Springer Verlag , Aug. 1991 . 6 . A. Colmerauer . Metamorphosis Grammars , volume 63 , pages 133 -LCB- 189 . SpringerVerlag , 1978 . 7 . A. Colmerauer , H. Kanoui , R. Pasero , and P. Roussel . Un systeme de communication homme-machine en francais . Technical report , Groupe d'Intelligence Artificielle , Universite d'Aix-Marseille II , Marseille , 1973 . 8 . V. Dahl . Translating spanish into logic through logic . American Journal of Computational Linguistics , 13:149 -LCB- 164 , 1981 . 9 . V. Dahl . Discontinuous grammars . Computational Intelligence , 5 -LRB- 4 -RRB- :161 -LCB- 179 , 1989 . 10 . J.-M . Jacquet and L. Monteiro . Comparative semantics for a parallel contextual logic programming language . In S. Debray and M. Hermenegildo , editors , Proceedings of the 1990 North American Conference on Logic Programming , pages 195 -LCB- 214 , Cambridge , Massachusetts London , England , 1990 . MIT Press . 11 . J. W. Lloyd . Foundations of Logic Programming . Springer-Verlag , 1987 . 12 . J. Lobo , J. Minker , and A. Rajasekar . Extending the semantics of logic programs to disjunctive logic programs . In G. Levi and M. Martelli , editors , Proceedings of the Sixth International Conference on Logic Programming , pages 255 -LCB- 267 , Cambridge , Massachusetts London , England , 1989 . MIT Press . 13 . J. Maluszy?nski . On the relationship between context-dependent grammars and multi-headed clauses. , June 1994 . Personal Communication . 14 . D. Miller . A logic programming language with lambda-abstraction , function variables , and simple unification . J. Logic and Computation , 1 -LRB- 4 -RRB- :497 -LCB- 536 , 1991 . 15 . D. A. Miller . Lexical scoping as universal quantification . In G. Levi and M. Martelli , editors , Proceedings of the Sixth International Conference on Logic Programming , pages 268 -LCB- 283 , Cambridge , Massachusetts London , England , 1989 . MIT Press . 16 . L. Monteiro and A. Porto . Contextual logic programming . In G. Levi and M. Martelli , editors , Proceedings of the Sixth International Conference on Logic Programming , pages 284 -LCB- 299 , Cambridge , Massachusetts London , England , 1989 . MIT Press . 17 . F. Pereira . Extraposition grammars . American Journal for Computational Linguistics , 7:243 -LCB- 256 , 1981 . 18 . M. Proietti . On the definition of binarization in terms of fold/unfold . , June 1994 . Personal Communication . 19 . M. Proietti and A. Pettorossi . Unfolding-definition-folding , in this order , for avoiding unnecessary variables in logic programs . In J. Maluszy?nski and M. Wirsing , editors , Proceedings of the 3rd Int . Symposium on Programming Language Implementation and Logic Programming , PLILP91 , Passau , Germany , number 528 in Lecture Notes in Computer Science , pages 347 -LCB- 358 . Springer Verlag , Aug. 1991 . 20 . P. Prusinkiewicz and J. Hanan . L-systems : from formalism to programming languages . Springer-Verlag , 1992 . 21 . D. W. Reed , D. W. Loveland , and B. T. Smith . An alternative characterization of disjunctive logic programs . In V. Saraswat and K. Ueda , editors , Logic Programming Proceedings of the 1991 International Symposium , pages 54 -LCB- 70 , Cambridge , Massachusetts London , England , 1991 . MIT Press . 22 . J. Stoy . Denotational Semantics : the Scott-Strachey Approach to Programming Language Theory . Cambridge , MA . The MIT Press , 1977 . 23 . P. Tarau . Program Transformations and WAM-support for the Compilation of Definite Metaprograms . In A. Voronkov , editor , Logic Programming , RCLP Proceedings , number 592 in Lecture Notes in Artificial Intelligence , pages 462 -LCB- 473 , Berlin , Heidelberg , 1992 . Springer-Verlag . 24 . P. Tarau and M. Boyer . Elementary Logic Programs . In P. Deransart and J. Ma luszy?nski , editors , Proceedings of Programming Language Implementation and Logic Programming , number 456 in Lecture Notes in Computer Science , pages 159 -LCB- 173 . Springer , Aug. 1990 . 25 . P. Tarau and K. De Bosschere . Memoing with Abstract Answers and Delphi Lemmas . In Y. Deville , editor , Logic Program Synthesis and Transformation , Springer - Verlag , Workshops in Computing , Louvain-la-Neuve , July 1993 . 26 . P. Wadler . Monads and composable continuations . Lisp and Symbolic Computation , pages 1 -LCB- 17 , 1993 . 27 . M. Wand . Continuation-based program transformation strategies . Journal of the Association for Computing Machinery , 27 -LRB- 1 -RRB- :164 -LCB- 180 , 1980 . 28 . D. H. D. Warren . Higher-order extensions to Prolog -LCB- are they needed ? In D. Michie , J. Hayes , and Y. H. Pao , editors , Machine Intelligence 10 . Ellis Horwood , 1981 . 29 . D. S. Warren . The XOLDT System . Technical report , SUNY Stony Brook , electronic document : ftp sbcs.sunysb.edu , 1992 . Appendix A % converts a multiple-head clause to its binary equivalent def_to_mbin -LRB- -LRB- H : - B -RRB- , M -RRB- : - ! , def_to_mbin0 -LRB- H , B , M -RRB- . def_to_mbin -LRB- H , M -RRB- : - def_to_mbin0 -LRB- H , true , M -RRB- . def_to_mbin0 -LRB- -LRB- H , Upper -RRB- , B , -LRB- HC : - BC -RRB- -RRB- : - nonvar -LRB- H -RRB- , ! , termcat -LRB- H , ContH , HC -RRB- , add_upper_cont -LRB- B , Upper , ContH , BC -RRB- . def_to_mbin0 -LRB- H , B , -LRB- HC : - BC -RRB- -RRB- : - ! , termcat -LRB- H , Cont , HC -RRB- , add_cont -LRB- B , Cont , BC -RRB- . add_upper_cont -LRB- B , Upper , ContH , BC -RRB- : - nonvar -LRB- Upper -RRB- , ! , add_cont -LRB- Upper , ContU , ContH -RRB- , add_cont -LRB- B , ContU , BC -RRB- . add_upper_cont -LRB- B , Upper , ContH , BC -RRB- : - add_cont -LRB- -LRB- strip_cont -LRB- ContH , Upper , ContU -RRB- , B -RRB- , ContU , BC -RRB- . % adds a continuation to a term add_cont -LRB- -LRB- true , Gs -RRB- , C , GC -RRB- : - ! , add_cont -LRB- Gs , C , GC -RRB- . add_cont -LRB- -LRB- fail , _ -RRB- , C , fail -LRB- C -RRB- -RRB- : - ! . add_cont -LRB- -LRB- G , Gs1 -RRB- , C , GC -RRB- : - ! , add_cont -LRB- Gs1 , C , Gs2 -RRB- , termcat -LRB- G , Gs2 , GC -RRB- . add_cont -LRB- G , C , GC -RRB- : - termcat -LRB- G , C , GC -RRB- . strip_cont -LRB- TC , T , C -RRB- : - TC = . . LC , append -LRB- L , -LSB- C -RSB- , LC -RRB- , ! , T = . . L . The predicate termcat -LRB- Term , Cont , TermAndCont -RRB- is a BinProlog builtin which works as if defined by the following clause : termcat -LRB- T , C , TC -RRB- : - T = . . LT , append -LRB- LT , -LSB- C -RSB- , LTC -RRB- , ! , TC = . . LTC . This article was processed using the LaTEX macro package with LLNCS style

O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I I I O O O O O O O O B I O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O

logic grammars
logic programming with continuations

continuation passing binary logic programs

program transformation based compilation