#include #include #include #include #include "/sys/src/libregexp/regcomp.h" #include "dfa.h" #define DUMP void dump(Dreprog *pp) { int i, j; Dreinst *l; print("start %ld %ld %ld %ld\n", pp->start[0]-pp->inst, pp->start[1]-pp->inst, pp->start[2]-pp->inst, pp->start[3]-pp->inst); for(i=0; ininst; i++){ l = &pp->inst[i]; print("%d:", i); for(j=0; jnc; j++){ print(" ["); if(j == 0) if(l->c[j].start > 1) print("\n", l->c[j].start); if(j != 0) print("%C%s", l->c[j].start&Runemax, (l->c[j].start&Dollar) ? "$" : ""); print("-"); if(j != l->nc-1) print("%C%s", (l->c[j+1].start&Runemax)-1, (l->c[j+1].start&Dollar) ? "$" : ""); print("] %ld", l->c[j].next - pp->inst); } if(l->isfinal) print(" final"); if(l->isloop) print(" loop"); print("\n"); } } void main(int argc, char **argv) { int i; Reprog *p; Dreprog *dp; i = 1; p = regcomp(argv[i]); if(p == 0){ print("=== %s: bad regexp\n", argv[i]); } // print("=== %s\n", argv[i]); // rdump(p); dp = dregcvt(p); print("=== dfa\n"); dump(dp); for(i=2; i