I want to test whether two languages have a string in common. Both of these languages are from a subset of regular languages described below and I only need to know whether there exists a string in both languages, not produce an example string.
The language is specified by a glob-like string like
/foo/**/bar/*.baz
where ** matches 0 or more characters, and * matches zero or more characters that are not /, and all other characters are literal.
Any ideas?
thanks,
mike
EDIT:
I implemented something that seems to perform well, but have yet to try a correctness proof. You can see the source and unit tests
Build FAs
AandBfor both languages, and construct the “intersection FA”AnB. IfAnBhas at least one accepting state accessible from the start state, then there is a word that is in both languages.Constructing
AnBcould be tricky, but I’m sure there are FA textbooks that cover it. The approach I would take is:AnBis the cartesian product of the states ofAandBrespectively. A state inAnBis written(a, b)whereais a state inAandbis a state inB.(a, b) ->r (c, d)(meaning, there is a transition from(a, b)to(c, d)on symbolr) exists iffa ->r cis a transition inA, andb ->r dis a transition inB.(a, b)is a start state inAnBiffaandbare start states inAandBrespectively.(a, b)is an accepting state inAnBiff each is an accepting state in its respective FA.This is all off the top of my head, and hence completely unproven!