Mercurial > hg > Members > masakoha > testcode
annotate c/regexParser/main.cc @ 66:f8fb3b463f70
fix when '|' come procces
author | Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 04 Aug 2015 16:41:41 +0900 |
parents | 20b7d4e958bb |
children | 4842ca2cf8ee |
rev | line source |
---|---|
55 | 1 /* |
56
8901bc071d33
implement string() and literal()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
2 * <literal> ::= [a-z][A-Z][0-9] |
8901bc071d33
implement string() and literal()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
3 * <charClass> ::= '['<literal>'-'<literal>']' |
8901bc071d33
implement string() and literal()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
4 * <string> ::= <literal><literal>* |
58
4053c3e0fa7f
implement group()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
57
diff
changeset
|
5 * <group> ::= '('<regex>')' |
66
f8fb3b463f70
fix when '|' come procces
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
65
diff
changeset
|
6 * <regexAtom> ::= <literal>|<charClass>|<group> |
f8fb3b463f70
fix when '|' come procces
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
65
diff
changeset
|
7 * <regex> ::= <regexAtom>|<regexAtom>'*'|<regexAtom>'|'<regex>|<regexAtom><regex> |
55 | 8 */ |
9 | |
45 | 10 #include <stdio.h> |
56
8901bc071d33
implement string() and literal()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
11 #include <stdlib.h> |
8901bc071d33
implement string() and literal()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
12 #include <string.h> |
57
71b497d25273
fix literal()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
56
diff
changeset
|
13 |
63 | 14 typedef struct charClass { |
15 unsigned char table[256]; | |
16 struct utf8Range { | |
17 unsigned char *begin; | |
18 unsigned char *end; | |
64
e0ad6c145f89
remove some errors
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
19 struct utf8Range *next; |
63 | 20 } *rangeList; |
64
e0ad6c145f89
remove some errors
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
21 } CharClass, *CharClassPtr; |
63 | 22 |
56
8901bc071d33
implement string() and literal()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
23 typedef struct node { |
63 | 24 unsigned char type; |
25 union value { | |
26 charClass *cc; | |
27 unsigned char *string; | |
64
e0ad6c145f89
remove some errors
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
28 }; |
58
4053c3e0fa7f
implement group()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
57
diff
changeset
|
29 struct node *self; |
56
8901bc071d33
implement string() and literal()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
30 struct node *left; |
8901bc071d33
implement string() and literal()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
31 struct node *right; |
8901bc071d33
implement string() and literal()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
32 } Node, *NodePtr; |
52
a2826bf4e80a
remove magic number
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
51
diff
changeset
|
33 |
64
e0ad6c145f89
remove some errors
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
34 unsigned char *ptr; |
e0ad6c145f89
remove some errors
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
35 unsigned char tokenType; |
e0ad6c145f89
remove some errors
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
36 int tokenValue; |
58
4053c3e0fa7f
implement group()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
57
diff
changeset
|
37 NodePtr regexHeadNode; |
4053c3e0fa7f
implement group()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
57
diff
changeset
|
38 |
56
8901bc071d33
implement string() and literal()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
39 NodePtr charClass(); |
8901bc071d33
implement string() and literal()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
40 NodePtr string(); |
58
4053c3e0fa7f
implement group()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
57
diff
changeset
|
41 NodePtr group(); |
63 | 42 NodePtr orexp(); |
56
8901bc071d33
implement string() and literal()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
43 NodePtr asterisk(); |
8901bc071d33
implement string() and literal()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
44 NodePtr regex(); |
57
71b497d25273
fix literal()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
56
diff
changeset
|
45 NodePtr createNode(char,NodePtr,NodePtr); |
64
e0ad6c145f89
remove some errors
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
46 extern void token(); |
e0ad6c145f89
remove some errors
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
47 extern NodePtr regexAtom(); |
e0ad6c145f89
remove some errors
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
48 |
55 | 49 |
62
a49b4a8b8c14
implement isLiteral
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
61
diff
changeset
|
50 bool isLiteral(char c) { |
63 | 51 if (*ptr > 0x7f) return true; |
52 else if (*ptr == '(') return false; | |
53 else if (*ptr == '[') return false; | |
54 else if (*ptr == '|') return false; | |
55 else if (*ptr == '*') return false; | |
56 return true; | |
62
a49b4a8b8c14
implement isLiteral
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
61
diff
changeset
|
57 } |
a49b4a8b8c14
implement isLiteral
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
61
diff
changeset
|
58 |
60
8616a045a7f4
impl asterisk
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
59 void printNodeDate(NodePtr n) { |
8616a045a7f4
impl asterisk
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
60 puts("---------------------"); |
64
e0ad6c145f89
remove some errors
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
61 // printf("Self Node char : %c\n", n->character); |
60
8616a045a7f4
impl asterisk
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
62 printf("Self Node addr : %p\n", n->self); |
8616a045a7f4
impl asterisk
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
63 printf("left Node addr : %p\n", n->left); |
8616a045a7f4
impl asterisk
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
64 printf("right Node addr : %p\n", n->right); |
8616a045a7f4
impl asterisk
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
65 puts("---------------------"); |
8616a045a7f4
impl asterisk
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
66 puts(""); |
8616a045a7f4
impl asterisk
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
67 } |
8616a045a7f4
impl asterisk
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
68 |
57
71b497d25273
fix literal()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
56
diff
changeset
|
69 NodePtr createNode(char character, NodePtr left, NodePtr right) { |
71b497d25273
fix literal()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
56
diff
changeset
|
70 NodePtr n = (NodePtr)malloc(sizeof(Node)); |
58
4053c3e0fa7f
implement group()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
57
diff
changeset
|
71 n->self = n; |
64
e0ad6c145f89
remove some errors
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
72 // n->character = character; |
56
8901bc071d33
implement string() and literal()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
73 n->left = left; |
8901bc071d33
implement string() and literal()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
74 n->right = right; |
58
4053c3e0fa7f
implement group()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
57
diff
changeset
|
75 |
60
8616a045a7f4
impl asterisk
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
76 printNodeDate(n); |
56
8901bc071d33
implement string() and literal()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
77 return n; |
8901bc071d33
implement string() and literal()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
78 } |
8901bc071d33
implement string() and literal()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
79 |
8901bc071d33
implement string() and literal()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
80 // <charClass> ::= '['<literal>'-'<literal>']' |
8901bc071d33
implement string() and literal()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
81 NodePtr charClass() { |
62
a49b4a8b8c14
implement isLiteral
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
61
diff
changeset
|
82 ptr++; |
a49b4a8b8c14
implement isLiteral
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
61
diff
changeset
|
83 NodePtr n = (NodePtr)malloc(sizeof(Node)); |
a49b4a8b8c14
implement isLiteral
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
61
diff
changeset
|
84 return n; |
56
8901bc071d33
implement string() and literal()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
85 } |
55 | 86 |
56
8901bc071d33
implement string() and literal()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
87 // <literal> ::= [a-z][A-Z][0-9] |
8901bc071d33
implement string() and literal()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
88 NodePtr literal() { |
65 | 89 NodePtr n = createNode(*ptr,0,0); |
57
71b497d25273
fix literal()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
56
diff
changeset
|
90 ptr++; |
71b497d25273
fix literal()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
56
diff
changeset
|
91 return n; |
56
8901bc071d33
implement string() and literal()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
92 } |
55 | 93 |
56
8901bc071d33
implement string() and literal()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
94 // <string> ::= <literal><literal>* |
8901bc071d33
implement string() and literal()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
95 NodePtr string() { |
8901bc071d33
implement string() and literal()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
96 char c = *ptr; |
58
4053c3e0fa7f
implement group()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
57
diff
changeset
|
97 NodePtr n = NULL; |
61
67cade0e35b0
impl isLiteral
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
60
diff
changeset
|
98 if (isLiteral(c)) { |
56
8901bc071d33
implement string() and literal()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
99 n = createNode(0,literal(),string()); |
55 | 100 } else { |
56
8901bc071d33
implement string() and literal()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
101 n = createNode(0,0,0); |
55 | 102 } |
58
4053c3e0fa7f
implement group()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
57
diff
changeset
|
103 return n; |
55 | 104 } |
105 | |
63 | 106 // <group> ::= '('<regex>')' |
58
4053c3e0fa7f
implement group()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
57
diff
changeset
|
107 NodePtr group() { |
63 | 108 token(); |
109 NodePtr n = regex(); | |
110 token(); | |
58
4053c3e0fa7f
implement group()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
57
diff
changeset
|
111 if (*ptr == ')') { |
63 | 112 n = createNode('(',n,0); |
58
4053c3e0fa7f
implement group()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
57
diff
changeset
|
113 } else { |
63 | 114 // ) reqiured |
58
4053c3e0fa7f
implement group()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
57
diff
changeset
|
115 } |
4053c3e0fa7f
implement group()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
57
diff
changeset
|
116 return n; |
4053c3e0fa7f
implement group()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
57
diff
changeset
|
117 } |
4053c3e0fa7f
implement group()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
57
diff
changeset
|
118 |
55 | 119 |
63 | 120 void token() { |
58
4053c3e0fa7f
implement group()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
57
diff
changeset
|
121 while (*ptr != '\0') { |
4053c3e0fa7f
implement group()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
57
diff
changeset
|
122 if ((*ptr == '(') || (*ptr == ')')) { |
63 | 123 tokenType = *ptr++; |
124 tokenValue = 0; | |
125 return ; | |
58
4053c3e0fa7f
implement group()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
57
diff
changeset
|
126 } else if (*ptr == '[') { |
63 | 127 tokenType = '['; |
64
e0ad6c145f89
remove some errors
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
128 tokenValue = *ptr; |
63 | 129 if (ptr[1] == ']') { |
130 ptr++; | |
131 } | |
132 while (*ptr != ']') ptr++; | |
133 ptr++; | |
134 return; | |
58
4053c3e0fa7f
implement group()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
57
diff
changeset
|
135 } else if (*ptr == '|'){ |
63 | 136 tokenType = '|'; |
137 tokenValue = 0; | |
138 return; | |
60
8616a045a7f4
impl asterisk
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
139 } else if (*ptr == '*'){ |
63 | 140 tokenType = '*'; |
141 tokenValue = 0; | |
142 return; | |
56
8901bc071d33
implement string() and literal()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
143 } |
63 | 144 |
145 tokenType = 'a'; | |
64
e0ad6c145f89
remove some errors
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
146 tokenValue = *ptr; |
65 | 147 return; |
63 | 148 |
149 if (*ptr == '\\') ptr++; // need more proccesing | |
150 /* | |
151 \277 | |
152 \0xa5 | |
153 \[ | |
154 \\ | |
155 \utf-8 etc... | |
156 */ | |
157 | |
55 | 158 } |
159 } | |
160 | |
64
e0ad6c145f89
remove some errors
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
161 // <regexAtom> ::= <literal>|<charClass>|<group> |
e0ad6c145f89
remove some errors
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
162 NodePtr regexAtom() { |
e0ad6c145f89
remove some errors
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
163 |
e0ad6c145f89
remove some errors
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
164 token(); |
e0ad6c145f89
remove some errors
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
165 NodePtr n = NULL; |
e0ad6c145f89
remove some errors
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
166 if (tokenType == 'a') n = literal(); |
e0ad6c145f89
remove some errors
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
167 else if (tokenType == '[') n = charClass(); |
e0ad6c145f89
remove some errors
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
168 else if (tokenType == '(') n = group(); |
e0ad6c145f89
remove some errors
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
169 |
e0ad6c145f89
remove some errors
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
170 return n; |
e0ad6c145f89
remove some errors
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
171 } |
e0ad6c145f89
remove some errors
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
172 |
e0ad6c145f89
remove some errors
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
173 // <regex> ::= <regexAtom>|<regexAtom>'*'|<regexAtom>'|'<regex>|<regexAtom><regex> |
e0ad6c145f89
remove some errors
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
174 NodePtr regex() { |
e0ad6c145f89
remove some errors
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
175 NodePtr n = regexAtom(); |
e0ad6c145f89
remove some errors
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
176 while (*ptr) { |
e0ad6c145f89
remove some errors
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
177 token(); |
e0ad6c145f89
remove some errors
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
178 if (tokenType == '*') { |
66
f8fb3b463f70
fix when '|' come procces
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
65
diff
changeset
|
179 n = createNode('*',n,0); ptr++; |
64
e0ad6c145f89
remove some errors
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
180 } else if (tokenType == '|') { |
66
f8fb3b463f70
fix when '|' come procces
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
65
diff
changeset
|
181 ptr++; |
64
e0ad6c145f89
remove some errors
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
182 NodePtr n1 = regex(); |
e0ad6c145f89
remove some errors
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
183 n = createNode('|',n,n1); |
e0ad6c145f89
remove some errors
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
184 } else { |
e0ad6c145f89
remove some errors
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
185 NodePtr n1 = regex(); |
e0ad6c145f89
remove some errors
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
186 n = createNode('+',n,n1); |
e0ad6c145f89
remove some errors
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
187 } |
e0ad6c145f89
remove some errors
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
188 } |
e0ad6c145f89
remove some errors
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
189 return n; |
e0ad6c145f89
remove some errors
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
190 } |
e0ad6c145f89
remove some errors
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
191 |
e0ad6c145f89
remove some errors
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
192 |
66
f8fb3b463f70
fix when '|' come procces
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
65
diff
changeset
|
193 /* |
f8fb3b463f70
fix when '|' come procces
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
65
diff
changeset
|
194 * e.g. |
f8fb3b463f70
fix when '|' come procces
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
65
diff
changeset
|
195 * |
f8fb3b463f70
fix when '|' come procces
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
65
diff
changeset
|
196 * % ./regexParser -regex abc |
f8fb3b463f70
fix when '|' come procces
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
65
diff
changeset
|
197 * |
f8fb3b463f70
fix when '|' come procces
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
65
diff
changeset
|
198 * #-c |
f8fb3b463f70
fix when '|' come procces
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
65
diff
changeset
|
199 * #-+ |
f8fb3b463f70
fix when '|' come procces
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
65
diff
changeset
|
200 * # #-b |
f8fb3b463f70
fix when '|' come procces
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
65
diff
changeset
|
201 * + |
f8fb3b463f70
fix when '|' come procces
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
65
diff
changeset
|
202 * #-a |
f8fb3b463f70
fix when '|' come procces
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
65
diff
changeset
|
203 * |
f8fb3b463f70
fix when '|' come procces
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
65
diff
changeset
|
204 * % ./regexParser -regex (a*|bc)d |
f8fb3b463f70
fix when '|' come procces
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
65
diff
changeset
|
205 * |
f8fb3b463f70
fix when '|' come procces
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
65
diff
changeset
|
206 * |
f8fb3b463f70
fix when '|' come procces
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
65
diff
changeset
|
207 * #-d |
f8fb3b463f70
fix when '|' come procces
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
65
diff
changeset
|
208 * + |
f8fb3b463f70
fix when '|' come procces
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
65
diff
changeset
|
209 * # #-c |
f8fb3b463f70
fix when '|' come procces
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
65
diff
changeset
|
210 * # #-+ |
f8fb3b463f70
fix when '|' come procces
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
65
diff
changeset
|
211 * # # #-b |
f8fb3b463f70
fix when '|' come procces
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
65
diff
changeset
|
212 * #-| |
f8fb3b463f70
fix when '|' come procces
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
65
diff
changeset
|
213 * # |
f8fb3b463f70
fix when '|' come procces
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
65
diff
changeset
|
214 * #-* |
f8fb3b463f70
fix when '|' come procces
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
65
diff
changeset
|
215 * #-a |
f8fb3b463f70
fix when '|' come procces
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
65
diff
changeset
|
216 * |
f8fb3b463f70
fix when '|' come procces
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
65
diff
changeset
|
217 */ |
f8fb3b463f70
fix when '|' come procces
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
65
diff
changeset
|
218 void printTree(NodePtr n) { |
f8fb3b463f70
fix when '|' come procces
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
65
diff
changeset
|
219 |
f8fb3b463f70
fix when '|' come procces
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
65
diff
changeset
|
220 } |
f8fb3b463f70
fix when '|' come procces
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
65
diff
changeset
|
221 |
f8fb3b463f70
fix when '|' come procces
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
65
diff
changeset
|
222 |
62
a49b4a8b8c14
implement isLiteral
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
61
diff
changeset
|
223 int main(int argc, char **argv) |
55 | 224 { |
56
8901bc071d33
implement string() and literal()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
225 for (int i = 1; i < argc; i++) { |
8901bc071d33
implement string() and literal()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
226 if (strcmp(argv[i],"-regex") == 0) { |
64
e0ad6c145f89
remove some errors
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
227 ptr = (unsigned char*)argv[i+1]; i++; |
56
8901bc071d33
implement string() and literal()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
228 } |
8901bc071d33
implement string() and literal()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
229 } |
55 | 230 |
56
8901bc071d33
implement string() and literal()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
231 printf("regex : %s\n",ptr); |
8901bc071d33
implement string() and literal()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
232 NodePtr n = regex(); |
66
f8fb3b463f70
fix when '|' come procces
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
65
diff
changeset
|
233 printTree(n); |
45 | 234 return 0; |
235 } |