Writing Context Free Grammar: Sabrina, Year 10

  • Thread starter Thread starter sabrina123456
  • Start date Start date
Click For Summary

Discussion Overview

The discussion revolves around writing a context-free grammar (CFG) for a specific language defined by strings that start with occurrences of one letter, followed by a character 'c', and ending with occurrences of another letter. The number of occurrences of 'c' is determined by a formula involving the counts of the first and second letters. The context includes both the formulation of the grammar and the understanding of the language it generates.

Discussion Character

  • Exploratory
  • Technical explanation
  • Debate/contested
  • Homework-related

Main Points Raised

  • Sabrina presents a CFG and describes the language as a^n c^(x.n + y.m + 1) b^m, providing examples of valid strings.
  • One participant expresses confusion about the number of 'c's generated by the formula, suggesting a possible typo in Sabrina's description.
  • Another participant critiques Sabrina's CFG, indicating that it contains errors and does not generate the specified language, suggesting a need for rules that connect the generation of 'a's and 'b's to the number of 'c's.
  • Sabrina expresses feelings of frustration and a desire for assistance in writing the CFG correctly.
  • A supportive response encourages Sabrina to maintain a positive attitude and offers to help explain the solution, while questioning her motivation for learning about CFGs.

Areas of Agreement / Disagreement

There is no consensus on the correctness of Sabrina's CFG, as participants point out errors and express confusion about the language definition. Multiple competing views on how to approach the grammar generation remain unresolved.

Contextual Notes

Participants note that the grammar must accurately reflect the language's structure, and there are indications of missing connections between the generation of letters and the character 'c'.

Who May Find This Useful

This discussion may be of interest to students learning about context-free grammars, educators looking for examples of CFG formulation, and individuals exploring theoretical computer science concepts.

sabrina123456
Messages
2
Reaction score
0
I am sabrina, year 10 at school. I have question of how to write Context free grammar >

The set of all strings beginning with a string of occurrences of the first letter specified above, and ending with a string of occurrences
of the second letter specified above. In the middle is a string of the character
c. If the number of occurrence of the first letter is n and the number of
occurrence of the second letter is m, then the number of occurrences of c is x.n
+ y.m + 1.
For example, the language is a^n c^x.n + y.m + 1b^m, with x=2, y=3,
and includes accccccbb and aacccccb.

And this is what I actually wrote below to write the context free grammar:

S -> ABC
A - > Aa
A - > a
B - > Bb
A - > b
C - > c

is this correct? Please I need help and i am trying to learn my best. Thank you for your help.

Regards

Sabrina
 
Physics news on Phys.org
sabrina123456 said:
For example, the language is a^n c^x.n + y.m + 1b^m, with x=2, y=3,
and includes accccccbb and aacccccb.

I'm a bit confused, because if the language is anc2n+3m+1cm, then for n = 1 and m = 2 (for the first example above) we should get 2n+3m+1 = 2+6+1 = 9 c's but in the example there are only 6. Likewise for the second there should be 8 c's but there are 5 in the example. Perhaps you made a typo somewhere?

sabrina123456 said:
And this is what I actually wrote below to write the context free grammar:

S -> ABC
A - > Aa
A - > a
B - > Bb
A - > b
C - > c

is this correct?

No. It has (what appears as) some "spelling mistakes", but even if you fix this it will not generate the specified language. For the grammar to do that you should check that all string generated by the grammar are in the language and, visa versa, that all strings allowed by the language can be generated by the grammar.

You should try make a grammar that "ties" the generation of each a with the generation of x number of c's, and each generation of b with the generation of y number of c's, that is, you need some rules that generate the left, middle and the right part of the strings, where for instance the left part could be
L -> aLcx
L -> e
where e means empty. You then need to figure out what the middle and right part should be (hint: the middle part is responsible for generating the c's that is not generated by neither the left nor right part).
 
I am very depressed really :(. I understood what needs to be done, but I am afraid I do not how to write Context-Free Grammar properly, i tried my best to spend hours working this, but I really wish you could help.

Much appreciated for your support.


Regards

Sabrina
 
No need to be depressed about it. I assume you are doing this for your own fun (as the subject is not something people at your age normally would be required to understand) and if so you should keep it fun.

If you still want to give it a go, I (or someone else here) could give it a try explaining the solution which is not that difficult, but then I would like to know first for what purpose you need to know about context free grammars. Normally context free grammars are used in connection with designing computer languages and programs for handling these, but maybe you have another reason for wanting to know about it?
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 75 ·
3
Replies
75
Views
7K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 6 ·
Replies
6
Views
7K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 9 ·
Replies
9
Views
2K
  • · Replies 11 ·
Replies
11
Views
2K