WeChat: cstutorcs
QQ: 749389476
* Simple regular expression matching.
* The Practice of Programming
* Brian W. Kernighan, Rob Pike
* Modified by: Michael D. Brown
* Purpose: This library is a modified version of a KLEE tutorial adapted for academic use.
#include
static int matchhere(char*,char*);
static int matchstar(int c, char *re, char *text) {
if (matchhere(re, text))
} while (*text != ‘\0’ && (*text++ == c || c== ‘.’));
static int matchhere(char *re, char *text) {
if (re[1] == ‘*’)
return matchstar(re[0], re+2, text);
if (re[0] == ‘$’ && re[1]==’\0′)
return *text == ‘\0′;
if (*text!=’\0′ && (re[0]==’.’ || re[0]==*text))
return matchhere(re+1, text+1);
int match(char *re, char *text) {
if (re[0] == ‘^’)
return matchhere(re+1, text);
if (matchhere(re, text))
} while (*text++ != ‘\0’);
* Harness for testing with KLEE.
// The size of the buffer to test with.
#define SIZE 7
int main() {
// The input regular expression.
char re[SIZE];
// Make the input symbolic.
klee_make_symbolic(re, sizeof re, “re”);
// Tell KLEE to assume the symbolic input is a null-terminated string
klee_assume(re[SIZE – 1] == ‘\0’);
// Try to match against a constant string “hello”.
match(re, “cs6340”);