-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathregexp.p
97 lines (84 loc) · 1.25 KB
/
regexp.p
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import pyb_example_2
struct paren_t
{
int nalt
int natom
}
struct regexp{
//½«Ç°×º×ª»»³Éºó׺
char buf[1000]
char* rep2post(char * re)
{
struct paren_t paren[100]
struct paren_t* p = paren
int nalt = 0
int natom = 0
char *dst
dst = self->buf
while(*re != 0)
{
switch(*re)
{
case '(':
while(natom > 1){
--natom
*(dst++) = '.'
}
if(p >= paren + 100){
return NULL
}
p->nalt = nalt
p->natom = natom
p++
nalt = 0
natom = 0
case ')':
if(p == paren)
return NULL
if(natom == 0)
return NULL
while(--natom > 0)
*(dst++) = '.'
while(nalt > 0){
nalt--
*dst = '|'
}
--p
nalt = p->nalt
natom = p->natom
natom++
case '|':
if(natom == 0)
return NULL
while(--natom > 0)
*(dst++) = '.'
nalt++
case '*':
case '+':
case '?':
if(natom == 0)
return NULL
*(dst++) = *re
default :
if(natom > 1)
{
--natom
*(dst++) = '.'
}
*(dst++) = *re
natom++
}
re++
}
if(p != paren)
return NULL
while(--natom > 0)
*(dst++) = '.'
while(nalt > 0){
*(dst++) = '|'
nalt--
}
*dst = 0
return self->buf
}// end of re2post
}