comparison code/cbc/dfa.cbc @ 17:5ff3f1efa76a

add CbC test code.
author Ryoma SHINYA <shinya@firefly.cr.ie.u-ryukyu.ac.jp>
date Mon, 05 Jul 2010 06:26:20 +0900
parents
children
comparison
equal deleted inserted replaced
16:100efeeb2ad9 17:5ff3f1efa76a
1 #include <stdio.h>
2
3 __code state_0(char* s);
4 __code state_1(char* s);
5 __code state_2(char* s);
6 __code state_3(char* s);
7 __code accept(char* s);
8 __code reject(char* s);
9
10 int main(int argc, char* argv[]) {
11 puts("regexp: (A|B)*C");
12 puts("number of state: 4");
13 printf("string: %s\n", argv[1]);
14 goto state_1(argv[1]);
15
16 return 0;
17 }
18
19 __code state_0(char* s) {
20 switch(s++) {
21 case '\0':
22 goto accept(s);
23 default:
24 goto reject(NULL);
25 }
26 }
27
28 __code state_1(char* s) {
29 switch(s++) {
30 case 'A':
31 goto state_3(s);
32 case 'C':
33 goto state_0(s);
34 case 'B':
35 goto state_2(s);
36 default:
37 goto reject(NULL);
38 }
39 }
40
41 __code state_2(char* s) {
42 switch(s++) {
43 case 'A':
44 goto state_3(s);
45 case 'C':
46 goto state_0(s);
47 case 'B':
48 goto state_2(s);
49 default:
50 goto reject(NULL);
51 }
52 }
53
54 __code state_3(char* s) {
55 switch(s++) {
56 case 'A':
57 goto state_3(s);
58 case 'C':
59 goto state_0(s);
60 case 'B':
61 goto state_2(s);
62 default:
63 goto reject(NULL);
64 }
65 }
66
67
68 __code accept(char* s) {
69 printf("\nstring matches regexp. \n\n");
70 }
71
72 __code reject(char* s) {
73 printf("\nstring does not match regexp. \n\n");
74 }