-
-
Save martinwairegi/58293818a98e512105acf2f3461e3012 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Regex { | |
constructor() { | |
this.generate(); | |
} | |
/** | |
* Generate new regular expression and corresponding NFA | |
*/ | |
generate() { | |
this.postfix = ""; | |
this.regex = this.#kleene(7, 0.5, 0.2, 0.1); | |
this.nfa = this.#regexToNfa(this.postfix); | |
} | |
/** | |
* Convert regular expression into equivalent NFA using Thompson's construction | |
* @param {String} regex A regular expression in postfix | |
* @returns { | |
* Array<{ | |
* table: | |
* Array<{ | |
* stateID: Number, | |
* symbol: String, | |
* stateIDs: Array<Number> | |
* }>, | |
* start: Number, | |
* end: Array<Number> | |
* }> | |
* } State transition table for NFA accepting regex | |
* (alongside start state and accept states) | |
*/ | |
#regexToNfa(regex) { | |
// ... | |
} | |
/** | |
* Generate a random regular expression using probabilistic methods | |
* @param {Number} n Maximum depth of the regular expression tree | |
* @param {Number} p Literal probability | |
* @param {Number} s Concatenation probability | |
* @param {Number} k Kleene star probability | |
* @returns {String} Random regular expression | |
*/ | |
#kleene(n, p, s, k) { | |
// ... | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment