Skip to content

Instantly share code, notes, and snippets.

@robinhouston
Last active December 15, 2019 20:39
Show Gist options
  • Save robinhouston/95082374c4f20331f4cf46b1511d0106 to your computer and use it in GitHub Desktop.
Save robinhouston/95082374c4f20331f4cf46b1511d0106 to your computer and use it in GitHub Desktop.
var dfa = DFA.create();
var i, j;
for (i = 0; i <= 5; i++) for (j = 0; j <= 1; j++) {
dfa.addState(i + "." + j);
}
for (i = 0; i <= 5; i++) for (j = 0; j <= 1; j++) {
dfa.addTransition(i + "." + j, Math.min(5, i+1) + "." + Math.min(j+1, 1), C('c'));
dfa.addTransition(i + "." + j, Math.min(5, i+1) + "." + j, A(C('f'), C('a'), C('e'), C('t'), C('i'), C('o')));
}
for (i = 0; i <= 5; i++) for (j = 0; j <= 1; j++) {
var s = i + "." + j;
if (s != "0.0" && s != "5.1") dfa.eliminateState(s);
}
var regex = L(
S(dfa.transitionRegex("0.0", "0.0")),
dfa.transitionRegex("0.0", "5.1"),
S(dfa.transitionRegex("5.1", "5.1")),
);
console.log("^(" + regex.simplify().toString(false) + ")$");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment