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 |
#include "config.h" |
#include "config.h" |
21 |
#include <stdio.h> |
#include <stdio.h> |
22 |
#include <stdlib.h> |
#include <stdlib.h> |
32 |
|
|
33 |
#ifndef PDBG |
#ifndef PDBG |
34 |
#ifdef DEBUG_RE2 |
#ifdef DEBUG_RE2 |
35 |
#define PDBG(x) x |
#define PDBG(x) x |
36 |
#else |
#else |
37 |
#define PDBG(x) |
#define PDBG(x) |
38 |
#endif |
#endif |
39 |
#endif |
#endif |
40 |
|
|
68 |
#endif |
#endif |
69 |
|
|
70 |
/** |
/** |
71 |
* computes position, annulable, PP, DP attributes |
* computes position, annulable, PP, DP attributes |
72 |
* @param r = root |
* @param r = root |
73 |
* @param p = current leaf position |
* @param p = current leaf position |
74 |
* @param n = current node number |
* @param n = current node number |
124 |
} |
} |
125 |
|
|
126 |
/** |
/** |
127 |
* computes possuivante |
* computes possuivante |
128 |
* @param r = root |
* @param r = root |
129 |
* @param PS = next position |
* @param PS = next position |
130 |
*/ |
*/ |
143 |
case NODE_AND: |
case NODE_AND: |
144 |
/************************************/ |
/************************************/ |
145 |
/* \forall p \in DP(left) */ |
/* \forall p \in DP(left) */ |
146 |
/* PS[p] = PS[p] \cup PP(right) */ |
/* PS[p] = PS[p] \cup PP(right) */ |
147 |
/************************************/ |
/************************************/ |
148 |
for(pos=1; pos <= PS[0]; pos++) |
for(pos=1; pos <= PS[0]; pos++) |
149 |
{ |
{ |
155 |
/************************************/ |
/************************************/ |
156 |
/* == same as START */ |
/* == same as START */ |
157 |
/* \forall p \in DP(left) */ |
/* \forall p \in DP(left) */ |
158 |
/* PS[p] = PS[p] \cup PP(left) */ |
/* PS[p] = PS[p] \cup PP(left) */ |
159 |
/************************************/ |
/************************************/ |
160 |
for(pos=1; pos <= PS[0]; pos++) |
for(pos=1; pos <= PS[0]; pos++) |
161 |
{ |
{ |
166 |
case NODE_STAR: |
case NODE_STAR: |
167 |
/************************************/ |
/************************************/ |
168 |
/* \forall p \in DP(left) */ |
/* \forall p \in DP(left) */ |
169 |
/* PS[p] = PS[p] \cup PP(left) */ |
/* PS[p] = PS[p] \cup PP(left) */ |
170 |
/************************************/ |
/************************************/ |
171 |
for(pos=1; pos <= PS[0]; pos++) |
for(pos=1; pos <= PS[0]; pos++) |
172 |
{ |
{ |
223 |
case RE_CONS_MATCH: fprintf(f,"(:c: [%d])",l); break; |
case RE_CONS_MATCH: fprintf(f,"(:c: [%d])",l); break; |
224 |
case RE_USR1_MATCH: fprintf(f,"(:1: [%d])",l); break; |
case RE_USR1_MATCH: fprintf(f,"(:1: [%d])",l); break; |
225 |
case RE_USR2_MATCH: fprintf(f,"(:2: [%d])",l); break; |
case RE_USR2_MATCH: fprintf(f,"(:2: [%d])",l); break; |
226 |
default: |
default: |
227 |
if (l < RE_FINAL_TOK) |
if (l < RE_FINAL_TOK) |
228 |
fprintf(f," (%c [%d]) ",l + 'a' - 1, l); |
fprintf(f," (%c [%d]) ",l + 'a' - 1, l); |
229 |
else |
else |
230 |
fprintf(f," (liste %d)",l - RE_LIST_USER_END); |
fprintf(f," (liste %d)",l - RE_LIST_USER_END); |
231 |
break; |
break; |
246 |
case RE_CONS_MATCH: fprintf(f,":c:"); break; |
case RE_CONS_MATCH: fprintf(f,":c:"); break; |
247 |
case RE_USR1_MATCH: fprintf(f,":1:"); break; |
case RE_USR1_MATCH: fprintf(f,":1:"); break; |
248 |
case RE_USR2_MATCH: fprintf(f,":2:"); break; |
case RE_USR2_MATCH: fprintf(f,":2:"); break; |
249 |
default: |
default: |
250 |
if (l < RE_FINAL_TOK) |
if (l < RE_FINAL_TOK) |
251 |
fprintf(f,"%c",l + 'a' - 1); |
fprintf(f,"%c",l + 'a' - 1); |
252 |
else |
else |
253 |
fprintf(f,"l%d",l - RE_LIST_USER_END); |
fprintf(f,"l%d",l - RE_LIST_USER_END); |
254 |
break; |
break; |
288 |
n->position,n->annulable,n->PP,n->DP); |
n->position,n->annulable,n->PP,n->DP); |
289 |
} |
} |
290 |
} |
} |
291 |
#endif |
#endif |
292 |
|
|
293 |
/*//////////////////////////////////////////////// |
/*//////////////////////////////////////////////// |
294 |
////////////////////////////////////////////////*/ |
////////////////////////////////////////////////*/ |
296 |
#ifdef DEBUG_RE |
#ifdef DEBUG_RE |
297 |
static void print_tree_nodes(FILE* f, NODE* n, int detail) |
static void print_tree_nodes(FILE* f, NODE* n, int detail) |
298 |
{ |
{ |
299 |
if (n == NULL) |
if (n == NULL) |
300 |
return; |
return; |
301 |
|
|
302 |
print_tree_nodes(f,n->fg,detail); |
print_tree_nodes(f,n->fg,detail); |
303 |
print_tree_nodes(f,n->fd,detail); |
print_tree_nodes(f,n->fd,detail); |
319 |
|
|
320 |
print_tree_edges(f,n->fg); |
print_tree_edges(f,n->fg); |
321 |
print_tree_edges(f,n->fd); |
print_tree_edges(f,n->fd); |
322 |
|
|
323 |
switch (n->type) |
switch (n->type) |
324 |
{ |
{ |
325 |
case NODE_OR: |
case NODE_OR: |
345 |
void regexp_print_tree(NODE* n, char* name, int detail) |
void regexp_print_tree(NODE* n, char* name, int detail) |
346 |
{ |
{ |
347 |
FILE* f; |
FILE* f; |
348 |
pid_t pid; |
pid_t pid; |
349 |
|
|
350 |
f=fopen(name,"w"); |
f=fopen(name,"w"); |
351 |
fprintf(f,"digraph %s {\n",name); |
fprintf(f,"digraph %s {\n",name); |
352 |
print_tree_nodes(f,n,detail); |
print_tree_nodes(f,n,detail); |