What language generated by the following context-free grammar 1) S------> SaS | b i already know the answer to question one but to prove it would is be something like this: S -----> SaaS -----> baab which can also be express as the language b(ab)* or (ba)*b

Another question is what does | b mean does it mean substitute into S afterwards?

2) S ----> AA

A----> aA | Aa | b

So for this question how can i start this? Would it be like S----> AA ----> aAaA ----> aAaAaA -----> abababa ? SO the language would be (ab)*?

  • 1
    $\begingroup$ One question per question, please. The answer to many of these is covered by standard textbooks and by our reference materials. For instance, the ansewr to your first question (how to prove what the language is) is covered by cs.stackexchange.com/q/11315/755. Note that you can use LaTeX here to typeset mathematics in a more readable way. See here for a short introduction. $\endgroup$ – D.W. Apr 17 '16 at 19:43
  • $\begingroup$ Your question is a very basic one. Let me direct you towards our reference questions which cover some fundamentals you seem to be missing in detail. Please work through the related questions listed there, try to solve your problem again and edit to include your attempts along with the specific problems you encountered. Good luck! $\endgroup$ – Raphael Apr 17 '16 at 20:26
  • $\begingroup$ For the language in (2), note that $A$ can only derive strings with a single $A$, so $S$ can only derive strings of two $A$s, which will eventually yield strings with exactly two $b$s, so it can't be the language denoted by $(ab)^*$. $\endgroup$ – Rick Decker Apr 17 '16 at 23:42
  • $\begingroup$ @Rick Decker would the answer in #2 be (a+b)* ? since it can start with a or b and end with a or b which is almost similar to (ab)* $\endgroup$ – Darkflame May 1 '16 at 18:44
  • $\begingroup$ The language denoted by $(a+b)^*$ is not the same as the one denoted by $(ab)^*$. The former is all strings over $\{a,b\}$ and the latter is $\{\epsilon,ab,abab,ababab,\dotsc\}$. As I mentioned above, the language generated by your grammar consists of all strings with exactly two $b$s. $\endgroup$ – Rick Decker May 2 '16 at 12:47

The vertical bar indicates an alternative: $S\to SaS \mid b$ means there are two production rules in the grammar, $S\to SaS$ and $S\to b$. Since $b$ contains no variables it is like a final rule applied to a particular branch of the derivation-tree. But that does not mean the rule $S\to b$ has to be the postponed and applied to all occurrences of $S$ in the end.

| cite | improve this answer | |
  • $\begingroup$ ahhh okay that makes more sense the | b thx can you show me an example of when it doesn't have to apply at the end and is my work above a legit way of showing the language generated ? or do i need to show more than that $\endgroup$ – Darkflame Apr 17 '16 at 18:53
  • $\begingroup$ nvm about the rule applying at the end i think the 2nd question would be an example correct? $\endgroup$ – Darkflame Apr 17 '16 at 18:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.