Question

I have a DFA but I don't know whether it's accepting states. I only know the regular expression that it accepts. I'm trying to find whether it's accepting states, so I looked into each state of the DFA and I want to compare the accepting regex with the word generated by the current state.

So I'm looking for something that would compare the word with the regex and tell me if it matches, so I could mark this state of the DFA as an accepted state and move on to another state. I was trying to implement some algorithms but it has proven to be quite a complex problem for me. Can you advise me on this? Thanks!

Alphabet: {a,b,c}

Example regular expression: ab.(a|c)*

Was it helpful?

Solution

Take a look at this page: http://docs.oracle.com/javase/1.4.2/docs/api/java/util/regex/Pattern.html

It's seems like what you are look for is:

boolean isMatch = Pattern.matches("ab.(a|c)*", str);

OTHER TIPS

This is the Java tutorial on regular expression pattern matching : http://docs.oracle.com/javase/tutorial/essential/regex/intro.html

Is your problem specifically with the regular expressions, or with the DFA?

This is some example code for what you might want to do:

String state = WHATEVER THE DFA's state is

Pattern p = Pattern.compile("ab.(a|c)*");

Matcher m = p.matcher(state);

boolean isMatch = m.matches();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top