Mercurial > hg > Members > masakoha > testcode
annotate c/regexParser/main.cc @ 81:27883946b2dc
sort function
author | Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 07 Oct 2015 16:47:03 +0900 |
parents | 0a452d69f0e2 |
children | 1d9bbf922bb6 |
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>']' |
58
4053c3e0fa7f
implement group()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
57
diff
changeset
|
4 * <group> ::= '('<regex>')' |
66
f8fb3b463f70
fix when '|' come procces
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
65
diff
changeset
|
5 * <regexAtom> ::= <literal>|<charClass>|<group> |
f8fb3b463f70
fix when '|' come procces
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
65
diff
changeset
|
6 * <regex> ::= <regexAtom>|<regexAtom>'*'|<regexAtom>'|'<regex>|<regexAtom><regex> |
55 | 7 */ |
8 | |
45 | 9 #include <stdio.h> |
56
8901bc071d33
implement string() and literal()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
10 #include <stdlib.h> |
8901bc071d33
implement string() and literal()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
11 #include <string.h> |
77
7f53a587bf97
add regexParser.h
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
76
diff
changeset
|
12 #include "regexParser.h" |
76 | 13 |
81
27883946b2dc
sort function
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
80
diff
changeset
|
14 NodePtr createNode(unsigned char,NodePtr,NodePtr); |
27883946b2dc
sort function
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
80
diff
changeset
|
15 NodePtr charClass(RegexInfoPtr); |
27883946b2dc
sort function
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
80
diff
changeset
|
16 NodePtr group(RegexInfoPtr); |
27883946b2dc
sort function
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
80
diff
changeset
|
17 void token(RegexInfoPtr); |
27883946b2dc
sort function
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
80
diff
changeset
|
18 NodePtr regexAtom(RegexInfoPtr); |
80
0a452d69f0e2
remove global variable in main.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
79
diff
changeset
|
19 NodePtr regex(RegexInfoPtr); |
79
52da06c3f050
add printTree.cc & fix Makefile
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
20 extern void printTree(NodePtr); |
64
e0ad6c145f89
remove some errors
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
21 |
76 | 22 /** |
23 * Create a node of regex parse tree. | |
24 * tokenType | |
25 * regexPosition(state) | |
26 * stateTransitionTable | |
27 */ | |
67
4842ca2cf8ee
print character
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
66
diff
changeset
|
28 NodePtr createNode(unsigned char character, NodePtr left, NodePtr right) { |
57
71b497d25273
fix literal()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
56
diff
changeset
|
29 NodePtr n = (NodePtr)malloc(sizeof(Node)); |
58
4053c3e0fa7f
implement group()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
57
diff
changeset
|
30 n->self = n; |
67
4842ca2cf8ee
print character
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
66
diff
changeset
|
31 n->Value.character = character; |
56
8901bc071d33
implement string() and literal()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
32 n->left = left; |
8901bc071d33
implement string() and literal()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
33 n->right = right; |
8901bc071d33
implement string() and literal()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
34 return n; |
8901bc071d33
implement string() and literal()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
35 } |
8901bc071d33
implement string() and literal()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
36 |
8901bc071d33
implement string() and literal()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
37 // <charClass> ::= '['<literal>'-'<literal>']' |
80
0a452d69f0e2
remove global variable in main.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
79
diff
changeset
|
38 NodePtr charClass(RegexInfoPtr ri) { |
62
a49b4a8b8c14
implement isLiteral
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
61
diff
changeset
|
39 NodePtr n = (NodePtr)malloc(sizeof(Node)); |
80
0a452d69f0e2
remove global variable in main.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
79
diff
changeset
|
40 unsigned char startChar = ri->ptr[0]; |
0a452d69f0e2
remove global variable in main.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
79
diff
changeset
|
41 while (ri->ptr[0] == '-') { |
0a452d69f0e2
remove global variable in main.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
79
diff
changeset
|
42 ri->ptr++; |
67
4842ca2cf8ee
print character
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
66
diff
changeset
|
43 } |
80
0a452d69f0e2
remove global variable in main.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
79
diff
changeset
|
44 unsigned char endChar = ri->ptr[0]; |
67
4842ca2cf8ee
print character
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
66
diff
changeset
|
45 unsigned char *charTable = (unsigned char*)malloc(sizeof(char)*256); |
4842ca2cf8ee
print character
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
66
diff
changeset
|
46 |
62
a49b4a8b8c14
implement isLiteral
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
61
diff
changeset
|
47 return n; |
56
8901bc071d33
implement string() and literal()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
48 } |
55 | 49 |
56
8901bc071d33
implement string() and literal()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
50 // <literal> ::= [a-z][A-Z][0-9] |
80
0a452d69f0e2
remove global variable in main.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
79
diff
changeset
|
51 NodePtr literal(RegexInfoPtr ri) { |
0a452d69f0e2
remove global variable in main.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
79
diff
changeset
|
52 NodePtr n = createNode(ri->ptr[0],0,0); |
0a452d69f0e2
remove global variable in main.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
79
diff
changeset
|
53 ri->ptr++; |
57
71b497d25273
fix literal()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
56
diff
changeset
|
54 return n; |
56
8901bc071d33
implement string() and literal()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
55 } |
55 | 56 |
63 | 57 // <group> ::= '('<regex>')' |
80
0a452d69f0e2
remove global variable in main.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
79
diff
changeset
|
58 NodePtr group(RegexInfoPtr ri) { |
0a452d69f0e2
remove global variable in main.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
79
diff
changeset
|
59 return regex(ri); |
58
4053c3e0fa7f
implement group()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
57
diff
changeset
|
60 } |
4053c3e0fa7f
implement group()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
57
diff
changeset
|
61 |
55 | 62 |
71
58d2b10988c9
move ptr++ in token()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
70
diff
changeset
|
63 |
80
0a452d69f0e2
remove global variable in main.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
79
diff
changeset
|
64 void token(RegexInfoPtr ri) { |
0a452d69f0e2
remove global variable in main.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
79
diff
changeset
|
65 while (ri->ptr[0] != '\0') { |
0a452d69f0e2
remove global variable in main.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
79
diff
changeset
|
66 if (ri->ptr[0] == '('){ |
0a452d69f0e2
remove global variable in main.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
79
diff
changeset
|
67 ri->ptr++; |
0a452d69f0e2
remove global variable in main.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
79
diff
changeset
|
68 ri->tokenType = '('; |
0a452d69f0e2
remove global variable in main.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
79
diff
changeset
|
69 ri->tokenValue = 0; |
0a452d69f0e2
remove global variable in main.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
79
diff
changeset
|
70 if (ri->ptr[1] == ')') { |
0a452d69f0e2
remove global variable in main.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
79
diff
changeset
|
71 ri->ptr++; |
67
4842ca2cf8ee
print character
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
66
diff
changeset
|
72 } |
4842ca2cf8ee
print character
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
66
diff
changeset
|
73 return; |
80
0a452d69f0e2
remove global variable in main.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
79
diff
changeset
|
74 } else if (ri->ptr[0] == ')') { |
0a452d69f0e2
remove global variable in main.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
79
diff
changeset
|
75 ri->ptr++; |
0a452d69f0e2
remove global variable in main.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
79
diff
changeset
|
76 ri->tokenType = ')'; |
0a452d69f0e2
remove global variable in main.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
79
diff
changeset
|
77 ri->tokenValue = ri->ptr[0]; |
74 | 78 return; |
80
0a452d69f0e2
remove global variable in main.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
79
diff
changeset
|
79 } else if (ri->ptr[0] == '[') { |
0a452d69f0e2
remove global variable in main.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
79
diff
changeset
|
80 ri->ptr++; |
0a452d69f0e2
remove global variable in main.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
79
diff
changeset
|
81 ri->tokenType = '['; |
0a452d69f0e2
remove global variable in main.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
79
diff
changeset
|
82 ri->tokenValue = ri->ptr[0]; |
0a452d69f0e2
remove global variable in main.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
79
diff
changeset
|
83 if (ri->ptr[1] == ']') { |
0a452d69f0e2
remove global variable in main.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
79
diff
changeset
|
84 ri->ptr++; |
63 | 85 } |
86 return; | |
80
0a452d69f0e2
remove global variable in main.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
79
diff
changeset
|
87 } else if (ri->ptr[0] == '|'){ |
0a452d69f0e2
remove global variable in main.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
79
diff
changeset
|
88 ri->ptr++; |
0a452d69f0e2
remove global variable in main.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
79
diff
changeset
|
89 ri->tokenType = '|'; |
0a452d69f0e2
remove global variable in main.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
79
diff
changeset
|
90 ri->tokenValue = 0; |
63 | 91 return; |
80
0a452d69f0e2
remove global variable in main.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
79
diff
changeset
|
92 } else if (ri->ptr[0] == '*'){ |
0a452d69f0e2
remove global variable in main.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
79
diff
changeset
|
93 ri->ptr++; |
0a452d69f0e2
remove global variable in main.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
79
diff
changeset
|
94 ri->tokenType = '*'; |
0a452d69f0e2
remove global variable in main.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
79
diff
changeset
|
95 ri->tokenValue = 0; |
63 | 96 return; |
80
0a452d69f0e2
remove global variable in main.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
79
diff
changeset
|
97 } else if (ri->ptr[0] == '\\'){ |
73 | 98 // need more proccesing |
99 /* | |
100 \277 | |
101 \0xa5 | |
102 \[ | |
103 \\ | |
104 \utf-8 etc... | |
105 */ | |
106 } else { | |
80
0a452d69f0e2
remove global variable in main.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
79
diff
changeset
|
107 ri->tokenType = 'a'; |
0a452d69f0e2
remove global variable in main.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
79
diff
changeset
|
108 ri->tokenValue = ri->ptr[0]; |
73 | 109 return; |
56
8901bc071d33
implement string() and literal()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
110 } |
55 | 111 } |
71
58d2b10988c9
move ptr++ in token()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
70
diff
changeset
|
112 |
80
0a452d69f0e2
remove global variable in main.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
79
diff
changeset
|
113 ri->tokenType = 0; |
0a452d69f0e2
remove global variable in main.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
79
diff
changeset
|
114 ri->tokenValue = 0; |
71
58d2b10988c9
move ptr++ in token()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
70
diff
changeset
|
115 return; |
55 | 116 } |
117 | |
64
e0ad6c145f89
remove some errors
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
118 // <regexAtom> ::= <literal>|<charClass>|<group> |
80
0a452d69f0e2
remove global variable in main.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
79
diff
changeset
|
119 NodePtr regexAtom(RegexInfoPtr ri) { |
64
e0ad6c145f89
remove some errors
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
120 |
80
0a452d69f0e2
remove global variable in main.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
79
diff
changeset
|
121 token(ri); |
64
e0ad6c145f89
remove some errors
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
122 NodePtr n = NULL; |
80
0a452d69f0e2
remove global variable in main.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
79
diff
changeset
|
123 if (ri->tokenType == 'a') n = literal(ri); |
0a452d69f0e2
remove global variable in main.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
79
diff
changeset
|
124 else if (ri->tokenType == '[') n = charClass(ri); |
0a452d69f0e2
remove global variable in main.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
79
diff
changeset
|
125 else if (ri->tokenType == '(') n = group(ri); |
64
e0ad6c145f89
remove some errors
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
126 |
e0ad6c145f89
remove some errors
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
127 return n; |
e0ad6c145f89
remove some errors
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
128 } |
e0ad6c145f89
remove some errors
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
129 |
e0ad6c145f89
remove some errors
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
130 // <regex> ::= <regexAtom>|<regexAtom>'*'|<regexAtom>'|'<regex>|<regexAtom><regex> |
80
0a452d69f0e2
remove global variable in main.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
79
diff
changeset
|
131 NodePtr regex(RegexInfoPtr ri) { |
0a452d69f0e2
remove global variable in main.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
79
diff
changeset
|
132 NodePtr n = regexAtom(ri); |
0a452d69f0e2
remove global variable in main.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
79
diff
changeset
|
133 while (ri->ptr[0]) { |
0a452d69f0e2
remove global variable in main.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
79
diff
changeset
|
134 token(ri); |
0a452d69f0e2
remove global variable in main.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
79
diff
changeset
|
135 if (ri->tokenType == '*') { |
71
58d2b10988c9
move ptr++ in token()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
70
diff
changeset
|
136 n = createNode('*',n,0); |
80
0a452d69f0e2
remove global variable in main.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
79
diff
changeset
|
137 } else if (ri->tokenType == '|') { |
0a452d69f0e2
remove global variable in main.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
79
diff
changeset
|
138 NodePtr n1 = regex(ri); |
64
e0ad6c145f89
remove some errors
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
139 n = createNode('|',n,n1); |
80
0a452d69f0e2
remove global variable in main.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
79
diff
changeset
|
140 } else if (ri->tokenType == ')') { |
74 | 141 return n; |
64
e0ad6c145f89
remove some errors
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
142 } else { |
80
0a452d69f0e2
remove global variable in main.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
79
diff
changeset
|
143 NodePtr n1 = regex(ri); |
64
e0ad6c145f89
remove some errors
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
144 n = createNode('+',n,n1); |
e0ad6c145f89
remove some errors
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
145 } |
67
4842ca2cf8ee
print character
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
66
diff
changeset
|
146 } return n; |
68
d27b3af1fe75
remove string()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
67
diff
changeset
|
147 } |
d27b3af1fe75
remove string()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
67
diff
changeset
|
148 |
66
f8fb3b463f70
fix when '|' come procces
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
65
diff
changeset
|
149 |
62
a49b4a8b8c14
implement isLiteral
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
61
diff
changeset
|
150 int main(int argc, char **argv) |
55 | 151 { |
80
0a452d69f0e2
remove global variable in main.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
79
diff
changeset
|
152 RegexInfoPtr ri = (RegexInfoPtr)malloc(sizeof(RegexInfo)); |
0a452d69f0e2
remove global variable in main.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
79
diff
changeset
|
153 |
56
8901bc071d33
implement string() and literal()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
154 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
|
155 if (strcmp(argv[i],"-regex") == 0) { |
80
0a452d69f0e2
remove global variable in main.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
79
diff
changeset
|
156 ri->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
|
157 } |
8901bc071d33
implement string() and literal()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
158 } |
55 | 159 |
80
0a452d69f0e2
remove global variable in main.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
79
diff
changeset
|
160 printf("regex : %s\n",ri->ptr); |
0a452d69f0e2
remove global variable in main.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
79
diff
changeset
|
161 NodePtr n = regex(ri); |
66
f8fb3b463f70
fix when '|' come procces
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
65
diff
changeset
|
162 printTree(n); |
45 | 163 return 0; |
164 } |