Language generated by a grammer

  • Thread starter Movingon
  • Start date
  • Tags
    Language
In summary: Thanks in advance!If you know the form of the grammar, you can determine that the language generated is L.
  • #1
Movingon
4
0
Ok I have a simple question. Let us say we have a formal grammar, let us take this simple example:

S → aSb
S → ab

This grammar generates language [itex]a^n b^n[/itex]. My question is, is there a way I can tell what kind of language this generates from the rules? I can of course apply the rules and find out this grammar can generate such a language but sometimes we may have more complex examples containing more rules. So my questions is, how can we then find out exactly the kind of language generated by a given grammar without having to manually apply rules as this may not be always practical? Thanks in advance!
 
Technology news on Phys.org
  • #2
"exactly the kind of language generated by a given grammar" is perhaps not precise enough to know exactly what kind of answer you want given any arbitrary grammar.

You can, by inspecting the form of the grammar and not manually applying the rules, probably determine which level of the Chomksy heirarchy the language resides in.

A few seconds of searching turns up one reasonable description of the heirarchy.
http://www.answers.com/topic/chomsky-hierarchy
There are many other well written descriptions of this out there.

If, as I suspect, you are looking for a more precise description of the language than this then I suspect the answer may be that you cannot determine this in every case by just inspecting the form of the grammar.
 
  • #3
Thanks. Yeah what I meant was describing more precisely and formally a language generated by a certain grammar, the Chomsky hierarchy I already know of. For example, you are given a grammar as follows: G = ({S, X}, {a, b}, P, S) with the rules:
P = {S → aaSbb | X | ε, X → Xb | ε}.

where ε here stands for the empty string. You are asked to find out and describe formally the language generated by this grammar. As it turns out, this grammar generates language [itex] L = {a^n b^{2n+m} | n \geq 0, m \geq 0}[/itex]

So my question is, how could I, for example, figure out that this grammar generates this language? Do I have to apply those rules and then from the result find out the kind of language generated? Is this the only way to find out a language L generated by grammar G?
 

1. What is a grammar in relation to language generation?

A grammar is a set of rules that defines the structure and formation of a language. It specifies the correct way to form sentences and phrases in a language, including the use of words, punctuation, and grammar rules.

2. How is a grammar used to generate language?

A grammar is used as a framework or blueprint for generating language. It provides a set of rules that a computer program can follow to generate sentences and phrases that are grammatically correct and follow the structure of a particular language.

3. What is the difference between a context-free grammar and a context-sensitive grammar?

A context-free grammar is a type of grammar where the left-hand side of a production rule only contains a single non-terminal symbol, while a context-sensitive grammar allows multiple non-terminal symbols on the left-hand side of a production rule. This means that context-sensitive grammars are more powerful and can generate a wider range of languages.

4. Can a grammar generate an infinite number of sentences?

Yes, a grammar can generate an infinite number of sentences by using recursive rules. These are rules that can refer back to themselves, allowing for the creation of endless variations of sentences and phrases.

5. How is a grammar evaluated or tested for its effectiveness in generating language?

A grammar is evaluated by testing it with a variety of input sentences and checking if the output generated by the grammar is grammatically correct and follows the rules of the language. This process is known as parsing, and it helps identify any errors or limitations in the grammar's ability to generate language.

Similar threads

  • Programming and Computer Science
Replies
1
Views
1K
  • Programming and Computer Science
Replies
1
Views
273
  • Programming and Computer Science
Replies
8
Views
875
  • Programming and Computer Science
Replies
8
Views
2K
  • Programming and Computer Science
2
Replies
65
Views
2K
  • Set Theory, Logic, Probability, Statistics
Replies
26
Views
2K
  • Programming and Computer Science
4
Replies
107
Views
5K
  • Programming and Computer Science
Replies
1
Views
1K
  • Programming and Computer Science
Replies
10
Views
1K
  • General Discussion
2
Replies
40
Views
2K
Back
Top