CONTEXT FREE GRAMMAR
- Get link
- X
- Other Apps
-> In formal language theory, a context-free grammar (CFG) is a formal grammar whose production rules are of the form
with a single nonterminal symbol, and a string of terminals and/or nonterminals ( can be empty). A formal grammar is "context free" if its production rules can be applied regardless of the context of a nonterminal. No matter which symbols surround it, the single nonterminal on the left hand side can always be replaced by the right hand side. This is what distinguishes it from a context-sensitive grammar.
A formal grammar is essentially a set of production rules that describe all possible strings in a given formal language. Production rules are simple replacements. For example, the first rule in the picture,
T is the final set of a terminal symbol. It is denoted by lower case letters.
S is the start symbol which is used to derive the string. We can derive the string by repeatedly replacing a non-terminal by the right-hand side of the production until all non-terminal have been replaced by terminal symbols.
For the grammar given below, find out the context free language. The grammar G = ({S}, {a, b}, S, P) with the productions are;
S → aSa, (Rule: 1)
S → bSb (Rule: 2)
S → ε (Rule: 3)
First compute some strings generated by the production rules of the grammar G in the above;
⇒ aεa, (Rule: 3) i.e. ⇒ aa
⇒ abSba, (Rule: 2)
⇒ abεba (Rule: 3)
i.e. ⇒ abba
⇒ baSab, (Rule: 1)
⇒ ba ε ab (Rule: 3)
i.e. ⇒ baab
⇒ aaSaa, (Rule: 1)
⇒ aabSbaa, (Rule: 2)
⇒ aabbSbbaa, (Rule: 2)
⇒ aabb ε bbaa (Rule: 3)
i.e. ⇒ aabbbbaa
Hence; Language generated by the above grammar L(G) = {aa, bb, abba, baab, aabbaa, aabbbbaa,.. .. .. .. }
By analyzing the above generated string form the grammar G, there has a similar pattern in all computed strings, i.e.
- The length of the string is even always i.e. length of the string L(w) ≥ 2 × i | i = 1, 2, 3, 4.. .
- From the half length of the string, string is the reverser of each other side i.e. string is generated by the language is palindrome.
Thus we can write the language of the grammar L(G) = {wwR : w ∈ {a, b}*};
- Get link
- X
- Other Apps
Comments
Post a Comment