0

Could you explain me, how can I check, that the language of first context-free grammar (G1) is a subset of the language of second context-free grammar (G2).

G1 and G2 are two LL(1) grammars with identical alphabets:

{a, b, c, d, f}

Production rules are look like:

A -> αB 

or

A -> α 

and α is a non-epsilon string (of terminal symbols).

Context-free grammar G1:

S1 -> aK
K -> bC|cE
C -> cB|d
E -> bA|f
A -> abC
B -> acE

Context free grammar G2 :

S2 -> aX
X -> bZ|cY
Z -> cV|d
Y -> bU|f
V -> aQ
U -> aP
Q -> cY
P -> bZ

Automatic way is preferred.

In additional, how can I check that the languages of two arbitrary context-free grammars are equal.

Pu Vexi
  • 3
  • 3
  • Question also asked here: http://cs.stackexchange.com/questions/52495/how-can-i-check-that-the-language-of-one-context-free-grammar-is-a-subset-of-a-s – rici Jan 31 '16 at 04:11
  • In future, please do not cross-post questions. For more information, see [here](http://meta.stackexchange.com/q/64068). Since you have received answers to your question posted on the other site, I'm going to close this one (http://cs.stackexchange.com/questions/52495/how-can-i-check-that-the-language-of-one-context-free-grammar-is-a-subset-of-a-s). – Matt Feb 09 '16 at 21:34
  • I'm voting to close this question because it has already been asked, and answered, on cs.stackexchange.com, where it is "more" on topic. http://cs.stackexchange.com/questions/52495/how-can-i-check-that-the-language-of-one-context-free-grammar-is-a-subset-of-a-s – Matt Feb 09 '16 at 21:35

2 Answers2

1

Some questions that are undecidable for wider classes of grammars become decidable for context-free grammars

Language equality is one of the questions that open in cs and not decidable..

but in this case, you can actually build G1' as Greinbach normal form by Sheila Greibach,

then you can prove L(G2)=L(G1') by the use of SUBSTITUTION (in order to change the Variants names) on G1' and get exactly G2 grammer.

e.z.a
  • 71
  • 5
0

You actually can't. It's undecidable.

You can show that the problem of determining whether a grammar generates Σ* is undecidable. This means that it's undecidable to test whether two grammars produce the same language, because you could build a grammar for Σ* and testing whether another grammar generates the same language would then let you test whether a grammar has language Σ*, which we know we can't do. You also therefore can't test whether one grammar's language is a subset of another grammar's language, since if you could, you could test whether Σ* is a subset of the language of that grammar, which would then tell you whether the grammar could generate all strings.

Sorry about that!

templatetypedef
  • 362,284
  • 104
  • 897
  • 1,065