comparison CbC-examples/regexp/dfareg.c @ 62:70947ddafad7

added test code, CbC-example/regexp
author ryoma <e075725@ie.u-ryukyu.ac.jp>
date Sun, 25 Apr 2010 17:46:01 +0900
parents
children
comparison
equal deleted inserted replaced
61:60c1b2f8487a 62:70947ddafad7
1 #include <stdio.h>
2
3 #include <stdlib.h>
4
5 __code state_20_21(char* s);
6 __code state_1(char* s);
7 __code state_3_8_9_13_23_24(char* s);
8 __code state_6_7(char* s);
9 __code state_2_3_9_13_23_24_25(char* s);
10 __code state_10_11(char* s);
11 __code state_18_19(char* s);
12 __code state_4_5(char* s);
13 __code state_14_15(char* s);
14 __code state_3_9_13_22_23_24(char* s);
15 __code state_3_9_12_13_23_24(char* s);
16 __code state_16_17(char* s);
17 __code accept();
18 __code reject();
19
20 int main(int argc, char* argv[]) {
21 if (argc == 1) {
22 printf("usage: %s text\n", argv[0]);
23 exit(0);
24 }
25
26 puts("regexp: P(erl|HP|ython)*");
27 puts("number of state: 12");
28 printf("string: %s\n", argv[1]);
29 goto state_1(argv[1]);
30 return 0;
31 }
32
33 __code state_20_21(char* s) {
34 switch(*s++) {
35 case 'n':
36 goto state_3_9_13_22_23_24(s);
37 break;
38 default: goto reject();
39 }
40 }
41
42 __code state_1(char* s) {
43 switch(*s++) {
44 case 'P':
45 goto state_2_3_9_13_23_24_25(s);
46 break;
47 default: goto reject();
48 }
49 }
50
51 __code state_3_8_9_13_23_24(char* s) {
52 switch(*s++) {
53 case 'y':
54 goto state_14_15(s);
55 break;
56 case 'H':
57 goto state_10_11(s);
58 break;
59 case 'e':
60 goto state_4_5(s);
61 break;
62 case '\0': goto accept();
63 break;
64 default: goto reject();
65 }
66 }
67
68 __code state_6_7(char* s) {
69 switch(*s++) {
70 case 'l':
71 goto state_3_8_9_13_23_24(s);
72 break;
73 default: goto reject();
74 }
75 }
76
77 __code state_2_3_9_13_23_24_25(char* s) {
78 switch(*s++) {
79 case 'y':
80 goto state_14_15(s);
81 break;
82 case 'H':
83 goto state_10_11(s);
84 break;
85 case 'e':
86 goto state_4_5(s);
87 break;
88 case '\0': goto accept();
89 break;
90 default: goto reject();
91 }
92 }
93
94 __code state_10_11(char* s) {
95 switch(*s++) {
96 case 'P':
97 goto state_3_9_12_13_23_24(s);
98 break;
99 default: goto reject();
100 }
101 }
102
103 __code state_18_19(char* s) {
104 switch(*s++) {
105 case 'o':
106 goto state_20_21(s);
107 break;
108 default: goto reject();
109 }
110 }
111
112 __code state_4_5(char* s) {
113 switch(*s++) {
114 case 'r':
115 goto state_6_7(s);
116 break;
117 default: goto reject();
118 }
119 }
120
121 __code state_14_15(char* s) {
122 switch(*s++) {
123 case 't':
124 goto state_16_17(s);
125 break;
126 default: goto reject();
127 }
128 }
129
130 __code state_3_9_13_22_23_24(char* s) {
131 switch(*s++) {
132 case 'y':
133 goto state_14_15(s);
134 break;
135 case 'H':
136 goto state_10_11(s);
137 break;
138 case 'e':
139 goto state_4_5(s);
140 break;
141 case '\0': goto accept();
142 break;
143 default: goto reject();
144 }
145 }
146
147 __code state_3_9_12_13_23_24(char* s) {
148 switch(*s++) {
149 case 'y':
150 goto state_14_15(s);
151 break;
152 case 'H':
153 goto state_10_11(s);
154 break;
155 case 'e':
156 goto state_4_5(s);
157 break;
158 case '\0': goto accept();
159 break;
160 default: goto reject();
161 }
162 }
163
164 __code state_16_17(char* s) {
165 switch(*s++) {
166 case 'h':
167 goto state_18_19(s);
168 break;
169 default: goto reject();
170 }
171 }
172
173
174 __code accept() {
175 printf("\nstring matches regexp. \n\n");
176 }
177
178
179 __code reject() {
180 printf("\nstring does not match regexp. \n\n");
181 }
182