How can I check if the grammar is regular?

  • Context:
  • Thread starter Thread starter mathmari
  • Start date Start date
  • Tags Tags
    Regular
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
10 replies · 7K views
mathmari
Gold Member
MHB
Messages
4,984
Reaction score
7
I have the following grammars and I have to check if they are regular. Could you tell me how I can check this?

$G_1:$$$ I \to aK|bL$$
$$K \to bL| \varnothing$$
$$L \to dL|cK| \varnothing$$

$G_2:$$$ I \to KL$$
$$K \to aK|bK| \varnothing$$
$$L \to cL| dL| \varnothing$$

$G_3:$$$I \to II|(I)| \varnothing$$
 
Physics news on Phys.org
mathmari said:
I have the following grammars and I have to check if they are regular. Could you tell me how I can check this?

$G_1:$$$ I \to aK|bL$$
$$K \to bL| \varnothing$$
$$L \to dL|cK| \varnothing$$

$G_2:$$$ I \to KL$$
$$K \to aK|bK| \varnothing$$
$$L \to cL| dL| \varnothing$$

$G_3:$$$I \to II|(I)| \varnothing$$

Hey! :o

What is the definition of a regular grammar?
 
I like Serena said:
Hey! :o

What is the definition of a regular grammar?

The rules of a regular grammar are of the form:
$$ K \to \varnothing $$
$$ K \to aK' $$

At the second rule can it be $ K \to a K $ ?

At $G_2$ we have the rule $I \to KL$, that isn't of the form of one of the above rules, so $G_2$ is not a regular grammar, is it?

And $G_3$ for the same reason ($ I \to II$ ) is not a regular grammar.
 
mathmari said:
The rules of a regular grammar are of the form:
$$ K \to \varnothing $$
$$ K \to aK' $$

At the second rule can it be $ K \to a K $ ?

Yes.
If you read the context of the definition of a "right regular grammar", it should say that a rule of the second type has a single non-terminal on the left side, and a terminal followed by a non-terminal on the right hand side.
Note that a regular grammar is a left regular grammar or a right regular grammar.
At $G_2$ we have the rule $I \to KL$, that isn't of the form of one of the above rules, so $G_2$ is not a regular grammar, is it?

And $G_3$ for the same reason ($ I \to II$ ) is not a regular grammar.

Correct. ;)
 
I like Serena said:
Yes.
If you read the context of the definition of a "right regular grammar", it should say that a rule of the second type has a single non-terminal on the left side, and a terminal followed by a non-terminal on the right hand side.
Note that a regular grammar is a left regular grammar or a right regular grammar.

Correct. ;)

Great! Thanks! :o

And how can I check if the languages that these grammars generate are regular?
 
mathmari said:
Great! Thanks! :o

And how can I check if the languages that these grammars generate are regular?

From wiki: a regular grammar is a formal grammar that describes a regular language.

More specifically, they are the same!
Or formally: the definitions are equivalent.
 
I like Serena said:
From wiki: a regular grammar is a formal grammar that describes a regular language.

More specifically, they are the same!
Or formally: the definitions are equivalent.

So only the language that is generated from the first grammar is regular?
 
mathmari said:
So only the language that is generated from the first grammar is regular?

Eh... not exactly.
The languages generated by those other grammars might have another grammar that is regular.
 
I like Serena said:
Eh... not exactly.
The languages generated by those other grammars might have another grammar that is regular.

So do I have to find the languages that these grammars generate and then check if they are regular?
 
I like Serena said:
That would be a good way to go! (Angel)

Ok! Thanks! :o