17 |
/* along with this program; if not, write to the Free Software */ |
/* along with this program; if not, write to the Free Software */ |
18 |
/* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ |
/* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ |
19 |
|
|
|
/* $Id$ */ |
|
|
|
|
20 |
/** |
/** |
21 |
* \file regexp.c |
* \file regexp.c |
22 |
* \brief Regular Expression fonctions |
* \brief Regular Expression fonctions |
39 |
|
|
40 |
#ifndef PDBG |
#ifndef PDBG |
41 |
#ifdef DEBUG_RE2 |
#ifdef DEBUG_RE2 |
42 |
#define PDBG(x) x |
#define PDBG(x) x |
43 |
#else |
#else |
44 |
#define PDBG(x) |
#define PDBG(x) |
45 |
#endif |
#endif |
46 |
#endif |
#endif |
47 |
|
|
75 |
#endif |
#endif |
76 |
|
|
77 |
/** |
/** |
78 |
* computes position, annulable, PP, DP attributes |
* computes position, annulable, PP, DP attributes |
79 |
* @param r = root |
* @param r = root |
80 |
* @param p = current leaf position |
* @param p = current leaf position |
81 |
* @param n = current node number |
* @param n = current node number |
131 |
} |
} |
132 |
|
|
133 |
/** |
/** |
134 |
* computes possuivante |
* computes possuivante |
135 |
* @param r = root |
* @param r = root |
136 |
* @param PS = next position |
* @param PS = next position |
137 |
*/ |
*/ |
150 |
case NODE_AND: |
case NODE_AND: |
151 |
/************************************/ |
/************************************/ |
152 |
/* \forall p \in DP(left) */ |
/* \forall p \in DP(left) */ |
153 |
/* PS[p] = PS[p] \cup PP(right) */ |
/* PS[p] = PS[p] \cup PP(right) */ |
154 |
/************************************/ |
/************************************/ |
155 |
for(pos=1; pos <= PS[0]; pos++) |
for(pos=1; pos <= PS[0]; pos++) |
156 |
{ |
{ |
162 |
/************************************/ |
/************************************/ |
163 |
/* == same as START */ |
/* == same as START */ |
164 |
/* \forall p \in DP(left) */ |
/* \forall p \in DP(left) */ |
165 |
/* PS[p] = PS[p] \cup PP(left) */ |
/* PS[p] = PS[p] \cup PP(left) */ |
166 |
/************************************/ |
/************************************/ |
167 |
for(pos=1; pos <= PS[0]; pos++) |
for(pos=1; pos <= PS[0]; pos++) |
168 |
{ |
{ |
173 |
case NODE_STAR: |
case NODE_STAR: |
174 |
/************************************/ |
/************************************/ |
175 |
/* \forall p \in DP(left) */ |
/* \forall p \in DP(left) */ |
176 |
/* PS[p] = PS[p] \cup PP(left) */ |
/* PS[p] = PS[p] \cup PP(left) */ |
177 |
/************************************/ |
/************************************/ |
178 |
for(pos=1; pos <= PS[0]; pos++) |
for(pos=1; pos <= PS[0]; pos++) |
179 |
{ |
{ |
230 |
case RE_CONS_MATCH: fprintf(f,"(:c: [%d])",l); break; |
case RE_CONS_MATCH: fprintf(f,"(:c: [%d])",l); break; |
231 |
case RE_USR1_MATCH: fprintf(f,"(:1: [%d])",l); break; |
case RE_USR1_MATCH: fprintf(f,"(:1: [%d])",l); break; |
232 |
case RE_USR2_MATCH: fprintf(f,"(:2: [%d])",l); break; |
case RE_USR2_MATCH: fprintf(f,"(:2: [%d])",l); break; |
233 |
default: |
default: |
234 |
if (l < RE_FINAL_TOK) |
if (l < RE_FINAL_TOK) |
235 |
fprintf(f," (%c [%d]) ",l + 'a' - 1, l); |
fprintf(f," (%c [%d]) ",l + 'a' - 1, l); |
236 |
else |
else |
237 |
fprintf(f," (liste %d)",l - RE_LIST_USER_END); |
fprintf(f," (liste %d)",l - RE_LIST_USER_END); |
238 |
break; |
break; |
253 |
case RE_CONS_MATCH: fprintf(f,":c:"); break; |
case RE_CONS_MATCH: fprintf(f,":c:"); break; |
254 |
case RE_USR1_MATCH: fprintf(f,":1:"); break; |
case RE_USR1_MATCH: fprintf(f,":1:"); break; |
255 |
case RE_USR2_MATCH: fprintf(f,":2:"); break; |
case RE_USR2_MATCH: fprintf(f,":2:"); break; |
256 |
default: |
default: |
257 |
if (l < RE_FINAL_TOK) |
if (l < RE_FINAL_TOK) |
258 |
fprintf(f,"%c",l + 'a' - 1); |
fprintf(f,"%c",l + 'a' - 1); |
259 |
else |
else |
260 |
fprintf(f,"l%d",l - RE_LIST_USER_END); |
fprintf(f,"l%d",l - RE_LIST_USER_END); |
261 |
break; |
break; |
295 |
n->position,n->annulable,n->PP,n->DP); |
n->position,n->annulable,n->PP,n->DP); |
296 |
} |
} |
297 |
} |
} |
298 |
#endif |
#endif |
299 |
|
|
300 |
/*//////////////////////////////////////////////// |
/*//////////////////////////////////////////////// |
301 |
////////////////////////////////////////////////*/ |
////////////////////////////////////////////////*/ |
303 |
#ifdef DEBUG_RE |
#ifdef DEBUG_RE |
304 |
static void print_tree_nodes(FILE* f, NODE* n, int detail) |
static void print_tree_nodes(FILE* f, NODE* n, int detail) |
305 |
{ |
{ |
306 |
if (n == NULL) |
if (n == NULL) |
307 |
return; |
return; |
308 |
|
|
309 |
print_tree_nodes(f,n->fg,detail); |
print_tree_nodes(f,n->fg,detail); |
310 |
print_tree_nodes(f,n->fd,detail); |
print_tree_nodes(f,n->fd,detail); |
326 |
|
|
327 |
print_tree_edges(f,n->fg); |
print_tree_edges(f,n->fg); |
328 |
print_tree_edges(f,n->fd); |
print_tree_edges(f,n->fd); |
329 |
|
|
330 |
switch (n->type) |
switch (n->type) |
331 |
{ |
{ |
332 |
case NODE_OR: |
case NODE_OR: |
352 |
void regexp_print_tree(NODE* n, char* name, int detail) |
void regexp_print_tree(NODE* n, char* name, int detail) |
353 |
{ |
{ |
354 |
FILE* f; |
FILE* f; |
355 |
pid_t pid; |
pid_t pid; |
356 |
|
|
357 |
f=fopen(name,"w"); |
f=fopen(name,"w"); |
358 |
fprintf(f,"digraph %s {\n",name); |
fprintf(f,"digraph %s {\n",name); |
359 |
print_tree_nodes(f,n,detail); |
print_tree_nodes(f,n,detail); |