Removing Useless Productions of a Context Free Grammar through Petri Net

: Following the proposal for a Petri Net (PN) representation of the Context Free Grammar (CFG) [1] , we propose in this paper, an algorithm to eliminate the useless productions of CFG. First the CFG is represented by a PN. Then, based on the reachability, an algorithm is developed to eliminate Useless-productions. The algorithm is analyzed and implemented in Pascal using examples of a CFG. The proposed algorithm is better than the existing techniques in the sense that PN model is easy to understand and requires fewer computations and easily implemented on computers.


INTRODUCTION
Considerable interest has been shown in Petri Nets (PNs) as suitable models for representing and studying concurrent systems because of its potential advantages. The major use of Petri Net has been the modeling of systems in which it is possible for some events to occur concurrently and or sequentially. They have been found to be useful for describing and analyzing many systems such as production, automatic control, communication protocol, circuit analysis, physics and systems involving human activity such as management and office information systems, legal systems, teaching and knowledge representation [2][3][4][5][6] . In order to allow easy verification and hierarchical decomposition of the system, the reduction method of PNs without changing the properties has also been studied [7] . However, there are still some areas where either this versatile model has not been used at all or used to a very limited extent. Formal languages and automata theory is one of such areas. Algorithms to minimize the context free grammars using the Petri net concept have been published [1,8,9] in which a petri net representation of the CFG has been given and techniques to eliminate λ and unit-productions have been provided. The object of this paper is to exploit this PN model to remove Uselessproductions of a Context-Free Grammar (CFG). We assume that λand unit-productions have already been removed. First the CFG is represented by a PN. Then algorithm is developed to eliminate Uselessproductions. The algorithm is analyzed and implemented in Pascal. using examples of a CFG . The proposed technique is novel in the sense that it provides a better representation and understanding of the problem. It is simple, requires less computation and is easily implemented on computers. Another technique proposed in [3] in which a given finite or infinite labeled transition graphs defined by a graph grammar, in which an algorithm decides whether this graph is isomorphic to the reachable state graph of some finite unlabeled Petri net. The algorithm aims to produce a minimal net realizing the graph. In [10] the Petri net models are established for right linear grammar, expression grammar and property tree formal grammar. The structure algorithms of these models are given and the properties of models are discussed. It is aimed at generating a language process based on Petri net models. These models are intuitional and dynamic Petri net: A Petri net is an abstract, formal model of information flow [6] . PNs are composed of two basic components: a set of places, P and a set of transitions, T. The relationship between the places and the transitions are defined by the input and the output functions. The input function I defines, for each transition t j , the set of input places for the transition I(t j ). The output function O defines, for each transition t j , the set of output places for the transition O(t j ).
Formally, a Petri net C is defined as the four-tuple A Petri net graph is commonly used for better illustration. It consists of two types of nodes: a circle which represents a place and a bar which represents a transition. The input and output functions are represented by directed arcs from the places to the transitions and from the transitions to the places. An arc is directed from a place p j to a transition t i if the place is an input of the transition. Similarly, an arc is directed from a transition t j to a place p i if the place is an output of the transition.
To give a dynamic structure to PN, a marking µ is an assignment of tokens (represented by small solid dots inside the circles) to places. A Petri net executes by firing transitions. A transition is enabled to fire if each of its input places has at least one token in it. A transition fires by removing one token from each of its input places and depositing one token into each of its output places. Firing a transition will in general change the marking µ of the Petri net to a new marking µ′.
Context free grammar: Definition [11] : Let G = (V N , V T , S, F) be a grammar where V N is a finite set of variables, V T is a finite set of objects called terminal symbols, S ∈V N is a special symbol called the start variable and F is a finite set of productions. Then G is said to be context-free if productions in P have the form A → x, where A∈V N and x ∈(V N ∪V T ) * .
A context free grammar may have λ production, or unit productions. These productions make the grammar odd and difficult to parse. The useless productions have unnecessary variables and productions. Therefore eliminating these productions will make the grammar easier.
Theorem [11] : Let L be a context-free language that does not contain λ. Then there exists a context-free grammar that generates L and that does not have any useless productions. [8] : An equivalent grammar that does not contain any useless variables or productions can be obtained by first finding those variables which lead to terminal strings. This is done by defining the following sets 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 , the set of active variables A k is obtained.

Removing useless productions
Then only those variables which can be reached from starting symbol are obtained by defining and finding For some m, Rm -1 = R m , the set of reachable variables R m is obtained.
After that we eliminate all variables which do not belong in A k ∩ R m together with all rules in which they occur. The same process is repeated with the resulting grammar until we get a non-redundant grammar. [1]: A Context Free Grammar can be thought of as represented by interconnections of transitions and places of a PN. The productions are represented by transitions and the variables and terminal symbols by places. To include the order of appearance of variables and symbols on the right side of a production, the Petri net is modified and called an Ordered Petri Net (OPN).

PN Representation of a CFG
Definition [10] : Let G = (V N , V T , S, F) be a Context -Free Grammar. An Ordered Petri Net is a PN defined to represent G if and only if it has the following properties: * The input place of PN is labeled as S. * The output places are labeled from V T ∪ {λ}. * The intermediate places have labels from V N . * Production rules are represented by transitions. The input of the transition t j has label A ∈V N and outputs of t j are (from left to right ) labeled as a 1 , a 2 , ...., a n if and only if F has a production of the form A → a 1 , a 2 ,...., a n .
The string of output places with tokens by reading from left to right omitting any λ's encountered is called the yield of OPN.
It must be noted here that there will be exactly one input place for any transition. Two or more productions may have the same variable on the left side. Only one of these productions can be used in one derivation. Therefore, the corresponding transitions can not fire simultaneously. This is guaranteed by having the same place input to such transitions. To derive a sentence, it is sufficient to find the sequence of the transitions which must fire such that the token of the starting symbol place reaches the required output places of leaf nodes.

PROPOSED TECHNIQUE FOR REDUCTION OF USELESS PRODUCTIONS
Before developing the algorithm, some notations that require explanation and clear exposition are given below: P is the set of places corresponding to the variables and terminals. |P| = |(V N ∪V T )| P N is the set of places corresponding to the variables. P T is the set of places corresponding to the terminals. There are two types of useless productions; one is the production having their variables on the left side which cannot be reached from the starting symbol variables which do not lead to a terminal string. In the second type of productions the set of variables U which lead to terminal strings can be obtained by using reachability in PN. A place p i is in U iff a marking with a token in p i only can reach a marking with tokens only in leaf places by firing transitions. The second type of productions can be eliminated by finding the set of variables R which can be reached from starting symbol. A place p i is in R iff a token in S can reach to pi on firing transitions. Only those transitions, places given by a U ∩R along with their interconnections are included into resulting PN.

Algorithm
Input: OPN representing CFG with useless productions Output: A reduced OPN for CFG without useless productions Steps: {Steps 1-4 finds the set of variables U which lead to terminal strings} * If U i+1 ≠ U i then go to step 2.
* U = U i ; T ' 1 =T i+1 {Steps 5-8 find the set of variables R which can be reached from starting symbol} * R 0 ={S}; T 0 = ∅ ; i = 0 The order in t i o is to be maintained as before.

The algorithm can easily be shown to be O (T 2 )
where T is the number of productions. The algorithm is illustrated with the help of the following example, example 1.

CONCLUSION
In this paper an algorithm to eliminate the useless productions of CFG was given. It is based on the PN representation of a CFG and reachability concept of PN. The technique has been analyzed and implemented. The proposed algorithm is better than the existing techniques in the sense that PN model is easy to understand, requires less computations and easily amenable on computers. The algorithm accepts the required PN form of a CFG without λ and unit-