Reputation: 3768
I'm having trouble figuring out on deriving a regular grammar for a language that is recognised by a Finite Automata. The key issue I'm facing is the confusion between a regular grammar and a context free grammar. I can't seem to distinguish the difference between both of them and i find them very similar in some aspects such as ambiguity.
Could anyone please explain on how to derive a regular grammar for the language recognised by an FA?
Upvotes: 1
Views: 835
Reputation: 40
The way I understand it is that CFLs are a good way for describing infinite sets in a finite way and also for describing the syntax of languages.
CFLs and regular languages... All regular languages are context free, but not necessarily vice versa. Why?
We can prove this by using the pumping lemma, and pumping on the Context Free Language described by {a^n b^n | n ≥ 0} to show that it is not regular but it is a CFL because it is generated by the grammar G = (V, Σ, R, Start) where:
Note that a string w is derived ambiguously in a context-free grammar G if it has two or more different leftmost derivations. A grammar G is ambiguous if it generates some string ambiguously and sometimes, when we have an ambiguous grammar, we can find an unambiguous grammar that generates the same language. Note that some context-free languages can only be generated by ambiguous grammars - known as inherently ambiguous.
Also, any context-free language is generated by a context-free grammar in Chomsky Normal Form. To check whether a string is part of a CFL we can use the Cocke-Younger-Kasami algorithm.
A good read is Sipser, M. (2006). Introduction to the Theory of Computation (Vol. 2). Boston: Thomson Course Technology.
Upvotes: -1
Reputation: 28292
When we speak of regular grammars, we might be talking about (strictly) regular grammars or (extended) regular grammars. These distinct concepts correspond more or less exactly to DFAs and to generalized NFAs with empty transitions, respectively.
Furthermore, regular grammars are either right-regular or left-regular. I find right-regular grammars to be altogether easier to think about, but your mileage may vary.
Given a DFA, a (strictly) right-regular grammar can be produced as follows:
The above construction attempts to avoid adding unnecessary empty productions. If we don't mind having lots of empty productions, an alternative is to dispense with step 4 and in step 5, add transitions X := e if and only if X is an accepting state. This has the same effect.
Given a generalized NFA with empty transitions, an (extended) right-regular grammar can be produced as follows:
Basically, as in rici's linked answer, regular grammars are just an alternate notation for the same underlying information as is present in finite automata. This is fundamentally different from, say, regular expressions which are a fundamentally different (however equivalent) notation for representing regular languages.
Upvotes: 2