130 likes | 147 Views
CSC312 Automata Theory Lecture # 28 Chapter # 13 by Cohen Grammatical Format. Semiword: A semiword is a string of terminal (maybenone) concaenated with exactly one nonterminal (on the right). i.e. of the shape (terminal) (terminal) … (terminal)(Nonterminal) Theorem 22:
E N D
CSC312 Automata Theory Lecture # 28 Chapter # 13 by Cohen Grammatical Format
Semiword: A semiword is a string of terminal (maybenone) concaenated with exactly one nonterminal (on the right). i.e. of the shape (terminal) (terminal) … (terminal)(Nonterminal) Theorem 22: If all the productions in a given CFG fit one of the two forms: Nonterminal semiword or Nonterminal word ( where the word may be ), then the language generated by this CFG is regular.
Regular Grammar: A CFG is called a regular grammar if each of its productions is of one of the two forms Nonterminal semiword or Nonterminal word Example: Consider the CFG S aaS | bbS | Example: Consider the regular CFG S aaS | bbS | abX | baX | S aaS | bbS | abS | baS
NULL-Productions: -Productions The production of the form Non-terminal is said to be NULL production. Note: If a CFG has a Null production, then it is possible to construct another CFG without Null production accepting the same language with the exception of the word . Removing Null-Production: Delete all the Null productions and add new productions by substituting the in the old productions.
Example: Consider the CFG S aSbSa | Now remove the and add new productions as Old production New productions S aSbSa S aSba S abSa S aba So the new CFG without is S aSbSa |aSba | abSa | aba
Nullable-Productions: A production is called nullable if is of the form N or there is derivation that starts at N and leads to i.e. N1 N2 N3 … Nn where N1,N2,…,Nn are non-terminals Example: S AA | bB A aa | B B aS | .
Example: S AA | bB A aa | B B aS | Here S AA and A B are nullable productions while B is null production Removing Nullable-Production: Remove all -productions by substituting the in the old productions and also substitute for the nullable productions.
Example: S XY X Zb Y bW Z AB W Z A aA | bA | B Ba | Bb | Here A and B are null productions, whereas Z AB, W Z are nullable productions Now removing all the null productions we get the following new productions
Old productions New Productions S XY A a | b X Zb B a | b Y bW X b Z AB Y b W Z Z A (by substituting for B) A aA | bA Z B B Ba | Bb So the final CFG is S XY A aA | bA | a | b X Zb | b B Ba | Bb | a | b Y bW | b Z AB | A | B W Z
Unit Production: The production of the form nonterminal one terminal, is called unit production. Removing Unit Production: Examples: Consider the following CFG S A | bb A B | b B S | a Separate the unit production from non-unit productions. Now delete unit productions and add the new productions that can be generated by using the deleted unit productions.
Chomsky Normal Form (CNF): A CFG is said to be in CNF if it has all its productions of the form nonterminal string of two nonterminals nonterminal on terminal Note: Any CFG can be converted into CNF, if the null productions and the unit productions are remobed. Also if a CFG contains nullable productions as well then the corresponding new productions are also to be added.
Examples: Consider the following CFG S aSa | bSb | a | b | aa | bb Convert it into equivalent CNF. Steps for converting any CFG into CNF • Remove all the null and nullable productions • Kill all the unit productions • Convert all the productions of multiple letters into the form nonterminal string of two nonterminal by converting all terminal in strings of multiple letters into nonterminals and then introduce new productions in the form of pairs of nonterminals.