confusion about isEmpty()
miniHive opened this issue · 2 comments
miniHive commented
I am confused about Automaton.isEmpty(). I would think that the language defined by the regexp for the empty string "()" is the empty set.
I intentionally do not want to use "#" (for empty language) in the regular expression, because I would like to match against this symbol without having to escape.
The second assertion in my test below fails:
public void testEmptyString() throws REException {
int flags = RegExp.ALL & ~RegExp.EMPTY;
Automaton automaton = (new RegExp("()", flags)).toAutomaton();
RunAutomaton ra = new RunAutomaton(automaton);
assertTrue(ra.run(""));
assertTrue(automaton.isEmpty()); // fails
}
The compiled automaton is
initial state: 0
state 0 [accept]:
wangpeipei90 commented
The results you post actually show that the automation is not empty and the assert should fail in your case. It has one state which is the initial state, which starts from 0.
amoeller commented
The language defined by "()" is not empty, it contains one string (the empty string).