I need an algorithm that checks if the language of G1 is a subset of G2's language or not. (Assume G1 and G2 are two LL(1) grammars with identical alphabets whose production rules are either of the form A-->aB or A-->a , and "a" is a non-epsilon. I have a parsing algorithms that checking a grammar against a string but not checks against another language. Is there anyone who has a solution.
Asked
Active
Viewed 145 times
0
-
Is it homework? Anyway there is cs.stackexchange.com in case answers here are sparse. – NoDataDumpNoContribution Dec 20 '15 at 17:15
-
Generally, we check a grammar against an input string but the problem is, in this part we have 2 different grammar which may have a lot of production rules.So I think there should be a method or algorithm which I can use for example in java programming language. – saeedrobot Dec 20 '15 at 18:19
-
I know that it can be solved using two stacks, such that it checks if the FIRST of the string on top of the stack is a subset of the other one. Any recommended java code? – saeedrobot Dec 23 '15 at 16:24
1 Answers
1
Your grammars look like they're right regular. So the algorithm is to convert the grammars to NFAs. This is a trivial 1-1 mapping. Then convert the NFAs into DFAs with the subset construction. Call these A and B. It's easy to analyze them to determine L(A) subset? L(B). For example, since there are well known efficient algorithms for determining L(A) ==? L(B) and constructing a new machine I(A,B) that accepts L(A) intersection L(B), just compute
( L(I(A,B)) ==? L(A) ) or ( L(I(A,B)) ==? L(B) )

Gene
- 46,253
- 4
- 58
- 96