Structure preserving transformations on non-left-recursive grammars [chapter]

Anton Nijholt
1979 Lecture Notes in Computer Science  
INTROOUCTION ANO PRELIMINARIES If a context-free grammar is transformed to another context-free grammar in most of the cases it is quite obvious to demand weak equivalence for these two grammars. Transformations on context-free grammars can be defined for several reasons. Oependent on these reasons one may be interested in stronger relations of grammatical similarity. Instead of arbitrary context-free grammars one can consider context-free grammars which conform to some requiremeqts on, for
more » ... ple, the form of the productions. It is natural to ask whether each context-free language has a context-free grammar in this form and, if possible, how to transform a context-free grammar to a contextfree grammar of this special form. One of the reasons to consider normal forms may be the mathematical interest in how to generate a class of languages with a so simple possible grammatical description. Moreover, normal forms can simplify descriptions and proofs. Some normal form descriptions of the context-free grammars or their subclasses can be particularly amenable for parsing and this can be a strong motivation to transform grammars. Transformations can Pe applied to obtain grammars for which smaller sized parsers or faster parsing methods can be constructed. For such trans#ormations stronger relations than weak equivalence are desirable. A slightly stronger relation is obtained if we demand that the language preserving transformation is such that each sentence has the same number of parse trees in each grammar, that is, the transformation is also axr~guity preserving, Another relation which has been defined is structural equivalence, in which case it ms demanded that the parse trees o# the one grammar are the same, except for a relabeling o# the internal nodes, as the trees of the other grammar. Our interest is in the semantic equivalence of context-free grammars which are syntactically related. It is assumed that semantic rules are associated with each production of a grammar and, quite obvious, it follows that we will be interested in the correspondence of the derivations of related grammars. Such a correspondence should be formalized, Some rather independent developments can be distinguished, a. In the older literature one can find ideas and examples which come close to later formal concepts, for example Griffiths and Patrick [15], KurKi-Suonio [27], Kuno [26] and Poster [8]. Transformations have been defined in practically oriented situations of compiler construction. In such cases no general definit±ons of the syntactic relation between the grammars are presented. b. Gr~ar functor8 [X-~unctors] were introduced by Hotz [20,21] as special functors on categories associated with (general) phrase structure grammars. These syntax categories originate from work on switching circuits. The main concern has been to ~ind an algebraic ~rameworh ~or describ±ng general properties of phrase structure grammars. Only recently functors have been considered from a more "practicml" point of view. See ~or example Bertsch [3], Benson [2], Walter, KeKliKoglou and Kern [42] and Hetz [22]. c, Grocer covers, in the sense that we will use them here, were introduced about 1989 by Gray and Harrison [11] . A practical reason to consider covers concerns compiler construction. In such a case we consider a parse as the argument of e semantic mapping. In case a context-free grammar G' covers a context-free grammar G we can use the original semantic mappin~ corresponding to G, and do the parsing accordfng to G'. d. In the case of attribute grammars [see Knuth [24]] attributes are associated with the nodes of a parse tree. These attributes [which contain semantic information] are obtained from attributes associated with the symbols which appear in the productions and from attribute evaluation rules. I~ an attribute grammar is transformed to, for example, some normal form attribute grammar, we have not only the question of language equivalence but also the question of semantic equivalence. Such an equivalence is explored in Bochman [4,5]. We will be concerned with grammar covers, The ~irst part o~ this paper presents a general ~rameworK ~or covers. The second part introduces a transformation from non-le~t-recursive grammars to grammars in Greibach normal form. An investigation of the structure preserving properties of this transformation, which serves also as an illustration o~ our framework for covers, is presented. Preliminaries We shortly review some definitions and concepts of formal language theory. It is assumed that the reader is familiar with the basic results concerning context-free grammars and with parsing, otherwise see Aho and Ullman [I]. Let V be an ~p~bet and let ~ ~ V*, then l~I denotes the length of string ~. The ~ty string is denoted by ~. IT I~l ~ K then ~ : K denotes the suffix of ~ wlth The set of parse tree8 of G [with roots labeled with S and frontiers in E*] is densted by PTR[G]. If t e PTR(G] then fr(t] denotes its frontier. DEFINITION I.!. h CFG G = (N,Z,P,S] is a] proper, if G is E-free, cycle-free and G has no useless symbols. b] left-rec~sive, if there exist A ~ N and a ~ V such that A ~ As. c] in Greibach normal form [GNF], if P g N x ~N* u {[S,e]}. It is rather natural to start with a CFG G : (N,E,P,S] and generalize it to a simple syntax directed translation scheme (simple SOTS] T = [N,E,5,R,S], where 5[the output alphabet] contains the production numbers and R contains rules of the form A ~ ~,~' where A ~ ~ is in P and a' is a word over [N u A] which satisfies h A [~'] =
doi:10.1007/3-540-09510-1_35 fatcat:wvvmquewerhmniu5hx4tjmgzj4