How can I check if the grammar is regular?

  • MHB
  • Thread starter mathmari
  • Start date
  • Tags
    Regular
In summary: Ok! Thanks! :oIn summary, to check if a grammar is regular, we need to determine if it describes a regular language. This can be done by finding the language generated by the grammar and then checking if it is regular. The rules of a regular grammar are of the form: $$ K \to \varnothing $$$$ K \to aK' $$And a regular grammar can be either left regular or right regular.
  • #1
mathmari
Gold Member
MHB
5,049
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$$
 
Technology news on Phys.org
  • #2
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! :eek:

What is the definition of a regular grammar?
 
  • #3
I like Serena said:
Hey! :eek:

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.
 
  • #4
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. ;)
 
  • #5
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! :eek:

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

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.
 
  • #7
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?
 
  • #8
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.
 
  • #9
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?
 
  • #10
mathmari said:
So do I have to find the languages that these grammars generate and then check if they are regular?

That would be a good way to go! (Angel)
 
  • #11
I like Serena said:
That would be a good way to go! (Angel)

Ok! Thanks! :eek:
 

Related to How can I check if the grammar is regular?

1. How do I identify if a grammar is regular?

To identify if a grammar is regular, you can use one of the following methods:

  • Construct a deterministic finite automaton (DFA) for the grammar and check if it recognizes the language.
  • Apply the pumping lemma for regular languages to the grammar and see if it holds.
  • Convert the grammar into a regular expression and check if it represents the same language.

2. What are the basic characteristics of a regular grammar?

A regular grammar has the following characteristics:

  • It only contains terminal and non-terminal symbols.
  • Each production rule has only one non-terminal symbol on the left-hand side.
  • Each production rule has either a single terminal symbol or a single terminal symbol followed by a single non-terminal symbol on the right-hand side.
  • It is either left-linear or right-linear.

3. Can context-free grammars be regular?

No, context-free grammars cannot be regular. Regular grammars are a subset of context-free grammars, meaning that all regular grammars are also context-free grammars. However, not all context-free grammars are regular. Context-free grammars allow for more complex production rules, such as having multiple non-terminal symbols on the right-hand side or having terminals and non-terminals mixed together.

4. Are there any automated tools to check if a grammar is regular?

Yes, there are many tools available that can automatically check if a given grammar is regular. Some popular options include JFLAP, ANTLR, and YACC. These tools can also help with constructing DFAs or converting regular grammars to regular expressions.

5. Why is it important to check if a grammar is regular?

Checking if a grammar is regular is important because it allows us to determine the level of complexity of a language. Regular languages have very simple and predictable patterns, making them easier to analyze and manipulate. Additionally, knowing if a grammar is regular can help determine which algorithms and methods are best suited for working with that language.

Similar threads

  • Programming and Computer Science
Replies
13
Views
4K
  • Programming and Computer Science
Replies
8
Views
3K
  • Set Theory, Logic, Probability, Statistics
Replies
24
Views
4K
  • Programming and Computer Science
Replies
1
Views
1K
  • Set Theory, Logic, Probability, Statistics
Replies
12
Views
2K
Replies
19
Views
179
  • Introductory Physics Homework Help
Replies
30
Views
652
  • Set Theory, Logic, Probability, Statistics
Replies
1
Views
874
  • Programming and Computer Science
Replies
1
Views
2K
  • Calculus and Beyond Homework Help
Replies
13
Views
2K
Back
Top