# Theory of Computation – Regular Grammars

If all production of a CFG are of the form A -> wB or A -> w, where A and B are variables and w ϵ Vt*, then we say that grammar is right linear. If all production of a CFG are of the form A -> Bw or A -> w, we call it left linear. A right or left linear grammar is called a regular grammar.
Every regular expression can be represented by a regular grammar. As there is a finite automaton for every regular expression we can generate a finite automaton for the regular grammar.

Conversion of Regular Grammar into Finite Automata
Given a regular grammar G, a finite automata accepting L(G) can be obtained as follows:

1. The number of states in the automata will be equal to the number of non-terminals plus one. Each state in automata represents each non-terminal in the regular grammar. The additional state will be the final state of the automata. The state corresponding to the start symbol of the grammar will be the initial state of automata. If L(G) contains ϵ that is start symbol is grammar devices to ϵ, then make start state also as final state.
2. The transitions for automata are obtained as follows
1. For every production A -> aB make δ(A, a) = B that is make an are labeled ‘a’ from A to B.
2. For every production A -> a make δ(A, a) = final state.
3. For every production A -> ϵ, make δ(A, ϵ) = A and A will be final state.

Example:Give the automaton for the following grammar:
S -> 0S/1A/1
A -> 0A/1A/0/1
”Solution”

The automaton will have 3 states S, A, F
For production S -> 0S, S -> 1A, S -> 1

For production A -> 0A, A -> 1A, A -> 0, A -> 1.

Question: Consider the regular grammar G = (Vn, Vt, P, S), where Vn = {A, B, S}, Vt = {a, b} and P is defined as
S -> abA
S ->B
S -> baB
S -> ϵ
A -> bS
B -> aS
A -> b
Construct a NFA M such that L(M) = L(G).

The NFA M is

Sanfoundry Global Education & Learning Series – 100+ Theory of Computation Tutorials.

If you wish to look at all Tutorials and their examples, go to Theory of Computation Tutorials.

If you find any mistake above, kindly email to [email protected]
{"found_math": false, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "url": "https://www.sanfoundry.com/automata-theory-regular-grammars/", "fetch_time": 1719344825000000000, "content_mime_type": "text/html", "warc_filename": "crawl-data/CC-MAIN-2024-26/segments/1718198866218.13/warc/CC-MAIN-20240625171218-20240625201218-00347.warc.gz", "warc_record_offset": 851055649, "warc_record_length": 14842, "token_count": 583, "char_count": 2084, "score": 3.859375, "int_score": 4, "crawl": "CC-MAIN-2024-26", "snapshot_type": "latest", "language": "en", "language_score": 0.8689603805541992, "file_path": "/sailhome/yjruan/project/latent-lm/data/processed/finemath-4plus/finemath-4plus/train-00016-of-00064.parquet"}