# Finding the language generated for CFG

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)*?

• 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. – D.W. Apr 17 '16 at 19:43
• 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! – Raphael Apr 17 '16 at 20:26
• 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)^*$. – Rick Decker Apr 17 '16 at 23:42
• @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)* – Darkflame May 1 '16 at 18:44
• 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. – 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.