Journal of Compuer Science 3 (7): 494-498, 2007 ISSN 1549-3636 2007 Science Publicaions Removing Useless Producions of a Conex Free Grammar hrough Peri Ne Mansoor Al-A'ali and Ali A Khan Deparmen of Compuer Science, College of Informaion Technology, Universiy of Bahrain P.O. Box 32038, Sakheer Campus, Kingdom of Bahrain Absrac: Following he proposal for a Peri Ne (PN) represenaion of he Conex Free Grammar (CFG) [1], we propose in his paper, an algorihm o eliminae he useless producions of CFG. Firs he CFG is represened by a PN. Then, based on he reachabiliy, an algorihm is developed o eliminae Useless-producions. The algorihm is analyzed and implemened in Pascal using examples of a CFG. The proposed algorihm is beer han he exising echniques in he sense ha PN model is easy o undersand and requires fewer compuaions and easily implemened on compuers. Key words: Formal mehods, conex- free grammar, useless producions, peri ne Corresponding Auhor: INTRODUCTION Considerable ineres has been shown in Peri Nes (PNs) as suiable models for represening and sudying concurren sysems because of is poenial advanages. The major use of Peri Ne has been he modeling of sysems in which i is possible for some evens o occur concurrenly and or sequenially. They have been found o be useful for describing and analyzing many sysems such as producion, auomaic conrol, communicaion proocol, circui analysis, physics and sysems involving human aciviy such as managemen and office informaion sysems, legal sysems, eaching and knowledge represenaion [2-6]. In order o allow easy verificaion and hierarchical decomposiion of he sysem, he reducion mehod of PNs wihou changing he properies has also been sudied [7]. However, here are sill some areas where eiher his versaile model has no been used a all or used o a very limied exen. Formal languages and auomaa heory is one of such areas. Algorihms o minimize he conex free grammars using he Peri ne concep have been published [1,8,9] in which a peri ne represenaion of he CFG has been given and echniques o eliminae λ and uni- producions have been provided. The objec of his paper is o exploi his PN model o remove Uselessproducions of a Conex-Free Grammar (CFG). We assume ha λ- and uni- producions have already been removed. Firs he CFG is represened by a PN. Then algorihm is developed o eliminae Uselessproducions. The algorihm is analyzed and implemened in Pascal. using examples of a CFG. The proposed echnique is novel in he sense ha i provides a beer represenaion and undersanding of he problem. I is simple, requires less compuaion and is easily implemened on compuers. Anoher echnique proposed in [3] in which a given finie or infinie labeled ransiion graphs defined by a graph grammar, in which an algorihm decides wheher his graph is isomorphic o he reachable sae graph of some finie unlabeled Peri ne. The algorihm aims o produce a minimal ne realizing he graph. In [10] he Peri ne models are esablished for righ linear grammar, expression grammar and propery ree formal grammar. The srucure algorihms of hese models are given and he properies of models are discussed. I is aimed a generaing a language process based on Peri ne models. These models are inuiional and dynamic Peri ne: A Peri ne is an absrac, formal model of informaion flow [6]. PNs are composed of wo basic componens: a se of places, P and a se of ransiions, T. The relaionship beween he places and he ransiions are defined by he inpu and he oupu funcions. The inpu funcion I defines, for each ransiion j, he se of inpu places for he ransiion I( j ). The oupu funcion O defines, for each ransiion j, he se of oupu places for he ransiion O( j ). Formally, a Peri ne C is defined as he four-uple C = (P, T, I, O), where P = { p 1, p 2,..., p n } is a finie se of places T = { 1, 2,..., m } is a finie se of ransiions, P T =, I = P T, O = T P. Mansoor Al-A'ali, Deparmen of Compuer Science, College of Informaion Technology, Universiy of Bahrain, P.O. Box 32038, Sakheer Campus, Kingdom of Bahrain 494
A Peri ne graph is commonly used for beer illusraion. I consiss of wo ypes of nodes: a circle which represens a place and a bar which represens a ransiion. The inpu and oupu funcions are represened by direced arcs from he places o he ransiions and from he ransiions o he places. An arc is direced from a place p j o a ransiion i if he place is an inpu of he ransiion. Similarly, an arc is direced from a ransiion j o a place p i if he place is an oupu of he ransiion. To give a dynamic srucure o PN, a marking µ is an assignmen of okens (represened by small solid dos inside he circles) o places. A Peri ne execues by firing ransiions. A ransiion is enabled o fire if each of is inpu places has a leas one oken in i. A ransiion fires by removing one oken from each of is inpu places and deposiing one oken ino each of is oupu places. Firing a ransiion will in general change he marking µ of he Peri ne o a new marking µ. Conex free grammar: Definiion [11] : Le G = (V N, V T, S, F) be a grammar where V N is a finie se of variables, V T is a finie se of objecs called erminal symbols, S V N is a special symbol called he sar variable and F is a finie se of producions. Then G is said o be conex-free if producions in P have he form A x, where A V N and x (V N V T ) *. A conex free grammar may have λ producion, or uni producions. These producions make he grammar odd and difficul o parse. The useless producions have unnecessary variables and producions. Therefore eliminaing hese producions will make he grammar easier. Theorem [11] : Le L be a conex-free language ha does no conain λ. Then here exiss a conex-free grammar ha generaes L and ha does no have any useless producions. Removing useless producions [8] : An equivalen grammar ha does no conain any useless variables or producions can be obained by firs finding hose variables which lead o erminal srings. This is done by defining he following ses of variables A o = {X X P F and P V T *} A i = A i-1 {X X W F and W (V T A i-1 )*} For some k for which Ak -1 = A k, he se of acive variables A k is obained. Then only hose variables which can be reached from saring symbol are obained by defining and finding R o = {S} R i = R i-1 {Y X UYW F for some X R i-1 and U, W (V N V T )*} For some m, Rm -1 = R m, he se of reachable variables R m is obained. Afer ha we eliminae all variables which do no belong in A k R m ogeher wih all rules in which hey occur. The same process is repeaed wih he resuling grammar unil we ge a non-redundan grammar. PN Represenaion of a CFG [1]: A Conex Free Grammar can be hough of as represened by inerconnecions of ransiions and places of a PN. The producions are represened by ransiions and he variables and erminal symbols by places. To include he order of appearance of variables and symbols on he righ side of a producion, he Peri ne is modified and called an Ordered Peri Ne (OPN). Definiion [10] : Le G = (V N, V T, S, F) be a Conex - Free Grammar. An Ordered Peri Ne is a PN defined o represen G if and only if i has he following properies: * The inpu place of PN is labeled as S. * The oupu places are labeled from V T {λ}. * The inermediae places have labels from V N. * Producion rules are represened by ransiions. The inpu of he ransiion j has label A V N and oupus of j are (from lef o righ ) labeled as a 1, a 2,..., a n if and only if F has a producion of he form A a 1, a 2,..., a n. The sring of oupu places wih okens by reading from lef o righ omiing any λ's encounered is called he yield of OPN. I mus be noed here ha here will be exacly one inpu place for any ransiion. Two or more producions may have he same variable on he lef side. Only one of hese producions can be used in one derivaion. Therefore, he corresponding ransiions can no fire simulaneously. This is guaraneed by having he same place inpu o such ransiions. To derive a senence, i is sufficien o find he sequence of he ransiions which mus fire such ha he oken of he saring symbol place reaches he required oupu places of leaf nodes. 495
PROPOSED TECHNIQUE FOR REDUCTION OF USELESS PRODUCTIONS Before developing he algorihm, some noaions ha require explanaion and clear exposiion are given below: P is he se of places corresponding o he variables and erminals. P = (V N V T ) P N is he se of places corresponding o he variables. P T is he se of places corresponding o he erminals. T is he se of ransiions corresponding o he producions. T is he number of producions. i o is he se of oupu places of he ransiion i. I mus be noed ha he order of he places in j o is imporan and mus be in he same sequence in which hey appear in he corresponding producion rule. Furher i mus be mainained in subsequen operaions. o i is he se of inpu places of he ransiion i. Obviously his will conain only one elemen. p i o is he se of oupu ransiions of he place p i o pi is he se of inpu ransiions of he place p i P o = { p 1 o, p2 o,..., pn o }; o P={ o p1, o p2,..., o pn } T o = { 1 o, 2 o,..., n o }; o T={ o 1, o 2,..., o n } There are wo ypes of useless producions; one is he producion having heir variables on he lef side which canno be reached from he saring symbol variables which do no lead o a erminal sring. In he second ype of producions he se of variables U which lead o erminal srings can be obained by using reachabiliy in PN. A place p i is in U iff a marking wih a oken in p i only can reach a marking wih okens only in leaf places by firing ransiions. The second ype of producions can be eliminaed by finding he se of variables R which can be reached from saring symbol. A place p i is in R iff a oken in S can reach o pi on firing ransiions. Only hose ransiions, places given by a U R along wih heir inerconnecions are included ino resuling PN. Algorihm Inpu: OPN represening CFG wih useless producions Oupu: A reduced OPN for CFG wihou useless producions Seps: {Seps 1-4 finds he se of variables U which lead o erminal srings} * U 0 = ;T 0 = ; i = 0 * j T, if j o (Ui P T ) hen U i+1 = U i o j T i+1 =T i { j } * If U i+1 U i hen go o sep 2. * U = U i ; T ' 1 =T i+1 {Seps 5-8 find he se of variables R which can be reached from saring symbol} * R 0 ={S}; T 0 = ; i = 0 * j T ' 1 if o j R i hen R i+1 = R i ( j o PN ) T i+1 =T i { j } * If R i+1 R i i. hen go o sep 6 * P' N = U R i ; T ' N = T i+1 * {This finds he reduced OPN} ' i T' o ' i = i o ; o 'i = i o iff i T ' N o i = o i P' N ; i o = i o ( P'N P T ).The order in i o is o be mainained as before. The algorihm can easily be shown o be O ( T 2 ) where T is he number of producions. The algorihm is illusraed wih he help of he following example, example 1. Example 1: Consider he Grammar G = ({A, B, C, S}, {a, b, c}, S, F), wih he following producion rules: S ab bc; A BAc bsc a; B asb bbc; C SBC SBc ac The Peri ne presenaion is shown in Fig. 1 S 3 1 2 a B b C 5 4 6 b a c A 8 9 10 c b a Fig. 1: Peri Ne presenaion 7 c 496
For his example, P N = {S, A, B, C} ; P T ={ a, b, c}; T = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 } o 1 = {S}, 1 o = {a, B} o 2 = {S}, 2 o = {b, C} o 3 = {B}, 3 o = {a, S, B} o 4 = {B}, 4 o = {b, B, C} o 5 = {C}, 5 o = {a, c} o 6 = {C}, 6 o = {S,B,C} o 7 = {C}, 7 o = {S,B,c} o 8 = {A}, 8 o = {B, A, c} o 9 = {A}, 9 o = {b, S, C} o 10 = {A}, 10 o = {a} Seps 1-4 gives he following: U 0 = ;T 0 = ; i = 0 1 o, 2 o, 3 o and 4 o (U0 P T ) hence U 0 = ;T 0 = 5 o = {a, c} (U 0 P T ) hence U 1 = { o 5 }; U 1 = {C};T 1 ={ 5 } 6 o, 7 o, 8 o and 9 o (U 1 P T ) hence U 1 = {C};T 1 ={ 5 } 10 o = {a} (U 1 P T ) hence U 2 = {C,A};T 2 ={ 5, 10 } 1 o, 2 o, 3 o and 4 o (U0 P T ) 1 o (U2 P T ) hence U 2 = {C,A};T 2 ={ 5, 10 } 2 o (U2 P T ) hence U 3 = {C,A};T 3 ={ 2, 5, 10 } 3 o and 4 o (U3 P T ) hence U 3 = {C,A};T 3 ={ 2, 5, 10 } 5 o (U3 P T ) hence U 4 = {C,A};T 4 ={ 2, 5, 10 } 6 o, 7 o and 8 o (U 4 P T ) hence U 4 = {C,A};T 4 ={ 2, 5, 10 } Seps 5-8 gives he following: R 0 ={S}; T 0 = ; i = 0; T ' 1 ={ 2, 5, 9, 10 } P N = {S, A, B, C} o 2 ={S} R 0 hence R 1 = R 0 ( 2 o PN ) = {S} ({b, C} {S, A, B, C})={S,C} T 1 ={ 2 } o 5 R 1 hence R 2 = R 1 ( 5 o PN ) = {S,C} ({a, c} {S, A, B, C})={S,C} T 2 ={ 2, 5 } o 9 and o 10 R 2 ; R 2 ={S,C}; T 2 ={ 2, 5 } Since R 2 = R 1 hence P' N = U R i ={S,C} and T ' N = T i+1 ={ 2, 5 } Sep 9 gives: i T ' N ={ 2, 5 } o 2 = o 2 P' N = {S} {S,C}={S}; 2 o = 2 o ( P' N P T ) = {b, C} ( {S,C} { a, b, c} ) = {b,c} o 5 = o 5 P' N = {C} {S,C}={C} 5 o = 5 o ( P' N P T ) = {a,c} ( {S,C} { a, b, c}) = {a,c} Reduced Peri ne is shown in Fig. 2 and he corresponding reduced grammar is S bc; C ac o 9 (U 4 P T ) hence U 4 = {C,A,S};T 4 ={ 2, 5, 9, In his paper an algorihm o eliminae he useless 10 } producions of CFG was given. I is based on he PN represenaion of a CFG and reachabiliy concep of o 10 (U 4 P T ) hence U 5 = {C,A,S};T 5 ={ 2, 5, 9, PN. The echnique has been analyzed and implemened. 10 } The proposed algorihm is beer han he exising echniques in he sense ha PN model is easy o Since U 5 = U 4 = {C,A,S} hence U= {C,A,S}; T ' undersand, requires less compuaions and easily 1 =T 5 ={ 2, 5, 9, 10 } amenable on compuers. The algorihm acceps he required PN form of a CFG wihou λ and uni- 497 b 5 2 a S C Fig. 2: Reduced Peri ne c CONCLUSION
producions, removes he useless producions and gives he resul in PN form. The auomaed ranslaion of a CFG ino PN has no been provided, only a echnique has been given. REFERENCES 1. Khan, A.A., M. Al-A ali and N. Al-Shamlan, 1996. Simplificaion of Conex- Free Grammar Through Peri Ne. Compuers & Srucures, 58: 1055-1058. 2. Peerson, J.L., 1981. Peri Ne Theory and he Modeling of Sysems. Prenice Hall Inc. 3. Rennes, D.P., 2001. On he Peri ne realizaion of conex-free graphs. Theoreical Compuer Sci., 258: 573-98. 4. Tilak, A., 1979. Puing Peri Nes o Work. IEEE Compuer, pp: 85-94. 5. Yan, C., 1999. Peri Ne models of grammars and is srucure algorihm. J. Appl. Sci., 17: 58-63. 6. Esparza, J., 1997. Peri Nes, Commuaive Conex-Free Grammars and basic Parallel Processes. Fundamenal Informaicae, 31: 13-25. 7. Lee K.-H. and F. Joel, 1985. Hierarchical Reducion: Mehod for Analysis and Decomposiion of Peri Nes. IEEE Trans. on Sysems, Man and Cyberneics, SMC-15: 272-280. 8. Darondeau, P., 2001. On he Peri ne realizaion of conex-free graphs. Theor. Compuer Sci., 258: 573-598. 9. Erqing, X., 2004. A Pr/T-Ne model for conexfree language parsing, Fifh World Congress on Inelligen Conrol and Auomaion (IEEE Ca. No.04EX788), p. 3, 1919-22, Vol.3. 10. de Lara, J., 2004. Defining visual noaions and heir manipulaion hrough mea-modeling and graph ransformaion. J. Visual Languages and Compuing, 15: 309-30. 11. Linz, P., 1990. An Inroducion To Formal Languages And Auomaa, D.C. Heah and Company. 498