Mercurial > hg > Applications > Grep
comparison c/regexParser/regexParser.cc @ 119:2f0653f8eabb pairPro
fix
author | Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 26 Nov 2015 18:05:39 +0900 |
parents | 66c633575b53 |
children | aa266a4db47c |
comparison
equal
deleted
inserted
replaced
117:166136236891 | 119:2f0653f8eabb |
---|---|
1 #include <stdlib.h> | 1 #include <stdlib.h> |
2 #include <stdio.h> | 2 #include <stdio.h> |
3 #include "regexParser.h" | 3 #include "regexParser.h" |
4 #include "error.h" | 4 #include "error.h" |
5 | 5 |
6 static NodePtr createNode(RegexInfoPtr,unsigned char,NodePtr,NodePtr); | 6 static NodePtr createNode(RegexInfoPtr,NodePtr,NodePtr); |
7 static NodePtr charClass(RegexInfoPtr); | 7 static NodePtr charClass(RegexInfoPtr); |
8 static NodePtr group(RegexInfoPtr); | 8 static NodePtr group(RegexInfoPtr); |
9 static void token(RegexInfoPtr); | 9 static void token(RegexInfoPtr); |
10 static NodePtr regexAtom(RegexInfoPtr); | 10 static NodePtr regexAtom(RegexInfoPtr); |
11 NodePtr regex(RegexInfoPtr); | 11 NodePtr regex(RegexInfoPtr); |
23 n->cc->cond = (ConditionList)malloc(sizeof(Condition)); | 23 n->cc->cond = (ConditionList)malloc(sizeof(Condition)); |
24 return n; | 24 return n; |
25 } | 25 } |
26 | 26 |
27 static | 27 static |
28 NodePtr createNode(RegexInfoPtr ri,unsigned char character, NodePtr left, NodePtr right) { | 28 NodePtr createNode(RegexInfoPtr ri, NodePtr left, NodePtr right) { |
29 NodePtr n = allocateNode(); | 29 NodePtr n = allocateNode(); |
30 if (n == NULL) { | 30 if (n == NULL) { |
31 mallocFailedMessage(); | 31 mallocFailedMessage(); |
32 } | 32 } |
33 | 33 |
34 n->tokenType = ri->tokenType; | 34 n->tokenType = ri->tokenType; |
35 n->cc->cond->character = character; | 35 n->cc->cond->character = ri->tokenValue; |
36 n->left = left; | 36 n->left = left; |
37 n->right = right; | 37 n->right = right; |
38 | 38 |
39 if (ri->tokenType == 'a') { | 39 if (ri->tokenType == 'a') { |
40 n->nodeNumber = ri->nodeNumber; | 40 n->nodeNumber = ri->nodeNumber; |
58 } | 58 } |
59 | 59 |
60 // <literal> ::= [a-z][A-Z][0-9] | 60 // <literal> ::= [a-z][A-Z][0-9] |
61 static | 61 static |
62 NodePtr literal(RegexInfoPtr ri) { | 62 NodePtr literal(RegexInfoPtr ri) { |
63 NodePtr n = createNode(ri,ri->ptr[0],0,0); | 63 NodePtr n = createNode(ri,0,0); |
64 ri->ptr++; | 64 ri->ptr++; |
65 return n; | 65 return n; |
66 } | 66 } |
67 | 67 |
68 // <group> ::= '('<regex>')' | 68 // <group> ::= '('<regex>')' |
96 } | 96 } |
97 return; | 97 return; |
98 } else if (ri->ptr[0] == '|'){ | 98 } else if (ri->ptr[0] == '|'){ |
99 ri->ptr++; | 99 ri->ptr++; |
100 ri->tokenType = '|'; | 100 ri->tokenType = '|'; |
101 ri->tokenValue = 0; | 101 ri->tokenValue = '|'; |
102 return; | 102 return; |
103 } else if (ri->ptr[0] == '*'){ | 103 } else if (ri->ptr[0] == '*'){ |
104 ri->ptr++; | 104 ri->ptr++; |
105 ri->tokenType = '*'; | 105 ri->tokenType = '*'; |
106 ri->tokenValue = 0; | 106 ri->tokenValue = '*'; |
107 return; | 107 return; |
108 } else if (ri->ptr[0] == '\\'){ | 108 } else if (ri->ptr[0] == '\\'){ |
109 // need more proccesing | 109 // need more proccesing |
110 /* | 110 /* |
111 \277 | 111 \277 |
142 NodePtr regex(RegexInfoPtr ri) { | 142 NodePtr regex(RegexInfoPtr ri) { |
143 NodePtr n = regexAtom(ri); | 143 NodePtr n = regexAtom(ri); |
144 while (ri->ptr[0]) { | 144 while (ri->ptr[0]) { |
145 token(ri); | 145 token(ri); |
146 if (ri->tokenType == '*') { | 146 if (ri->tokenType == '*') { |
147 n = createNode(ri,'*',n,0); | 147 n = createNode(ri,n,0); |
148 } else if (ri->tokenType == '|') { | 148 } else if (ri->tokenType == '|') { |
149 NodePtr n1 = regex(ri); | 149 NodePtr n1 = regex(ri); |
150 n = createNode(ri,'|',n,n1); | 150 ri->tokenValue = '|'; |
151 n = createNode(ri,n,n1); | |
151 } else if (ri->tokenType == ')') { | 152 } else if (ri->tokenType == ')') { |
152 return n; | 153 return n; |
153 } else { | 154 } else { |
154 NodePtr n1 = regex(ri); | 155 NodePtr n1 = regex(ri); |
155 n = createNode(ri,'+',n,n1); | 156 ri->tokenValue = '+'; |
157 n = createNode(ri,n,n1); | |
156 } | 158 } |
157 } return n; | 159 } return n; |
158 } | 160 } |