Mercurial > hg > Applications > Grep
comparison c/regexParser/createRegexParser.cc @ 112:ec485345daf9 pairPro
some function use static
author | Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 23 Nov 2015 15:54:19 +0900 |
parents | 70069d4647a0 |
children |
comparison
equal
deleted
inserted
replaced
111:1d30f70702df | 112:ec485345daf9 |
---|---|
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 | 4 |
5 NodePtr createNode(RegexInfoPtr,unsigned char,NodePtr,NodePtr); | 5 static NodePtr createNode(RegexInfoPtr,unsigned char,NodePtr,NodePtr); |
6 NodePtr charClass(RegexInfoPtr); | 6 static NodePtr charClass(RegexInfoPtr); |
7 NodePtr group(RegexInfoPtr); | 7 static NodePtr group(RegexInfoPtr); |
8 void token(RegexInfoPtr); | 8 static void token(RegexInfoPtr); |
9 NodePtr regexAtom(RegexInfoPtr); | 9 static NodePtr regexAtom(RegexInfoPtr); |
10 NodePtr regex(RegexInfoPtr); | 10 NodePtr regex(RegexInfoPtr); |
11 | 11 |
12 /** | 12 /** |
13 * Create a node of regex parse tree. | 13 * Create a node of regex parse tree. |
14 * tokenType | 14 * tokenType |
15 * regexPosition(state) | 15 * regexPosition(state) |
16 * stateTransitionTable | 16 * stateTransitionTable |
17 */ | 17 */ |
18 | |
19 static | |
18 NodePtr createNode(RegexInfoPtr ri,unsigned char character, NodePtr left, NodePtr right) { | 20 NodePtr createNode(RegexInfoPtr ri,unsigned char character, NodePtr left, NodePtr right) { |
19 NodePtr n = (NodePtr)malloc(sizeof(Node)); | 21 NodePtr n = (NodePtr)malloc(sizeof(Node)); |
20 if (n == NULL) { | 22 if (n == NULL) { |
21 fprintf(stderr, "Failed to allocate memory.\n"); | 23 mallocFailedMessage(); |
22 exit(-1); | |
23 } | 24 } |
24 | 25 |
25 n->tokenType = ri->tokenType; | 26 n->tokenType = ri->tokenType; |
26 n->self = n; | 27 n->self = n; |
27 n->Value.character = character; | 28 n->Value.character = character; |
42 } | 43 } |
43 return n; | 44 return n; |
44 } | 45 } |
45 | 46 |
46 // <charClass> ::= '['<literal>'-'<literal>']' | 47 // <charClass> ::= '['<literal>'-'<literal>']' |
48 static | |
47 NodePtr charClass(RegexInfoPtr ri) { | 49 NodePtr charClass(RegexInfoPtr ri) { |
48 NodePtr n = (NodePtr)malloc(sizeof(Node)); | 50 NodePtr n = (NodePtr)malloc(sizeof(Node)); |
49 if (n == NULL) { | 51 if (n == NULL) { |
50 fprintf(stderr, "Failed to allocate memory.\n"); | 52 mallocFailedMessage(); |
51 exit(-1); | |
52 } | 53 } |
53 while (ri->ptr[0] == '-') { | 54 while (ri->ptr[0] == '-') { |
54 ri->ptr++; | 55 ri->ptr++; |
55 } | 56 } |
56 return n; | 57 return n; |
57 } | 58 } |
58 | 59 |
59 // <literal> ::= [a-z][A-Z][0-9] | 60 // <literal> ::= [a-z][A-Z][0-9] |
61 static | |
60 NodePtr literal(RegexInfoPtr ri) { | 62 NodePtr literal(RegexInfoPtr ri) { |
61 NodePtr n = createNode(ri,ri->ptr[0],0,0); | 63 NodePtr n = createNode(ri,ri->ptr[0],0,0); |
62 ri->ptr++; | 64 ri->ptr++; |
63 return n; | 65 return n; |
64 } | 66 } |
65 | 67 |
66 // <group> ::= '('<regex>')' | 68 // <group> ::= '('<regex>')' |
69 static | |
67 NodePtr group(RegexInfoPtr ri) { | 70 NodePtr group(RegexInfoPtr ri) { |
68 return regex(ri); | 71 return regex(ri); |
69 } | 72 } |
70 | 73 |
71 | 74 static |
72 | |
73 void token(RegexInfoPtr ri) { | 75 void token(RegexInfoPtr ri) { |
74 while (ri->ptr[0] != '\0') { | 76 while (ri->ptr[0] != '\0') { |
75 if (ri->ptr[0] == '('){ | 77 if (ri->ptr[0] == '('){ |
76 ri->ptr++; | 78 ri->ptr++; |
77 ri->tokenType = '('; | 79 ri->tokenType = '('; |
122 ri->tokenValue = 0; | 124 ri->tokenValue = 0; |
123 return; | 125 return; |
124 } | 126 } |
125 | 127 |
126 // <regexAtom> ::= <literal>|<charClass>|<group> | 128 // <regexAtom> ::= <literal>|<charClass>|<group> |
129 static | |
127 NodePtr regexAtom(RegexInfoPtr ri) { | 130 NodePtr regexAtom(RegexInfoPtr ri) { |
128 | 131 |
129 token(ri); | 132 token(ri); |
130 NodePtr n = NULL; | 133 NodePtr n = NULL; |
131 if (ri->tokenType == 'a') n = literal(ri); | 134 if (ri->tokenType == 'a') n = literal(ri); |