문제

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

도움이 되었습니까?

해결책

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);

다른 팁

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();
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top