Answer the question
In order to leave comments, you need to log in
What is the correct way to implement a regular expression without finite automata?
I'm trying through loops and arrays, that's what happened so far.
pastebin.com/Emu
At this stage, the goal is to implement at least one regular expression -
"+" - from 1 or more
. empty result.
The built-in class is not suitable, you need an explicit implementation.
Answer the question
In order to leave comments, you need to log in
Well, for starters, regular expressions and state machine are synonyms. On this, decide what exactly you want to do.
Somehow like that. Not very efficient, really. And no brackets.
static string FindReg(string src,string ptrn) {
int LP=ptrn.Length,LS=src.Length;
for(int i=0;i<LS;i++) {
int k=i;
bool ok=true;
for(int j=0;ok && j<LP;) {
int m=1;
bool plus=false;
char cur=ptrn[j++];
for(;j<LP;j++) {
if(ptrn[j]=='+') plus=true;
else if(ptrn[j]==cur) m++;
else break;
}
int s=0;
while(k+s<LS && src[k+s]==cur) s++;
if(s<m) {
ok=false; break;
} else if(plus) k+=s;
else k+=m;
}
if(ok) return src.Substring(i,k-i);
}
return null;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question