Mercurial > hg > Members > masakoha > testcode
annotate regexParser/node.cc @ 217:a9e3512120e2
NFA generation end
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 30 Dec 2015 18:37:01 +0900 |
parents | 4852bfa85db4 |
children | 3e78631a6222 |
rev | line source |
---|---|
79
52da06c3f050
add printTree.cc & fix Makefile
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1 #include <stdio.h> |
190
3e8e5780ad4a
change node::State to State
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
187
diff
changeset
|
2 #include "regexParser.h" |
117
166136236891
add header files
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
116
diff
changeset
|
3 #include "node.h" |
112
ec485345daf9
some function use static
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
110
diff
changeset
|
4 |
190
3e8e5780ad4a
change node::State to State
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
187
diff
changeset
|
5 void printCharacterClass(CharClassPtr cc, long nodeNumber,int d) { |
192
ecf70fb215a5
print charclass
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
190
diff
changeset
|
6 if (!cc) return; |
205
b7b8f0c03fe3
add test/ccMerge.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
195
diff
changeset
|
7 if (cc->type == 'a' || cc->type == 'r') { |
147 | 8 if (cc->left) { |
9 printCharacterClass(cc->left,nodeNumber,d+1); | |
10 } | |
135 | 11 printf("%*c",d*4, ' '); |
145
50217a0545e8
fix charClass()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
144
diff
changeset
|
12 for (RangeList range = cc->cond.range; range.begin != 0;) { |
144
d8a4922eceae
remove some errors (not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
139
diff
changeset
|
13 printf("[%c-%c] ",(unsigned char)range.begin,(unsigned char)range.end); |
145
50217a0545e8
fix charClass()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
144
diff
changeset
|
14 if (range.next != NULL) { |
50217a0545e8
fix charClass()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
144
diff
changeset
|
15 range = *range.next; |
50217a0545e8
fix charClass()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
144
diff
changeset
|
16 } else { |
50217a0545e8
fix charClass()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
144
diff
changeset
|
17 break; |
50217a0545e8
fix charClass()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
144
diff
changeset
|
18 } |
135 | 19 } |
214
a94f57af1600
remove allocateCCstate createCCState
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
212
diff
changeset
|
20 printf("(%lx)\n",cc->nextState.bitContainer); |
147 | 21 if (cc->right) { |
22 printCharacterClass(cc->right,nodeNumber,d+1); | |
23 } | |
135 | 24 } |
25 } | |
26 | |
190
3e8e5780ad4a
change node::State to State
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
187
diff
changeset
|
27 void descendTree(NodePtr n, int d) { |
134 | 28 if (n->left != NULL) { |
147 | 29 descendTree(n->left, d+1); |
79
52da06c3f050
add printTree.cc & fix Makefile
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
30 } |
135 | 31 if (n->tokenType == 'a') { |
131 | 32 printf("%*c",d*4, ' '); |
144
d8a4922eceae
remove some errors (not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
139
diff
changeset
|
33 for (int i = 0; i < n->cc->cond.w.length; i++) { |
d8a4922eceae
remove some errors (not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
139
diff
changeset
|
34 putchar(n->cc->cond.w.word[i]); |
131 | 35 } |
217 | 36 if (n->state && n->nextState) { |
216 | 37 printf("(%ld)->(%ld)\n",n->state->bitState.bitContainer,n->nextState->bitState.bitContainer); |
217 | 38 } else if (n->state) { |
39 printf("(%ld)\n",n->state->bitState.bitContainer); | |
216 | 40 } else { |
41 printf("\n"); | |
214
a94f57af1600
remove allocateCCstate createCCState
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
212
diff
changeset
|
42 } |
135 | 43 } else if (n->tokenType == 'c') { |
187
ef798db705e9
remove some warnings and errors(not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
174
diff
changeset
|
44 printCharacterClass(n->cc,n->stateNum,d); |
174
b9e913030a47
allocate nodeNumber to character and cclist (not allocate nodenumber '+' '*' '|')
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
167
diff
changeset
|
45 } else if (n->tokenType == 'a') { |
187
ef798db705e9
remove some warnings and errors(not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
174
diff
changeset
|
46 printf("%*c%c(%d)\n",d*4, ' ',n->tokenType,n->stateNum); |
135 | 47 } else { |
174
b9e913030a47
allocate nodeNumber to character and cclist (not allocate nodenumber '+' '*' '|')
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
167
diff
changeset
|
48 printf("%*c%c\n",d*4, ' ',n->tokenType); |
130
7925e9abb078
add or flag
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
120
diff
changeset
|
49 } |
89
50a146c05192
add NodeNumber in Regex Parser tree
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
79
diff
changeset
|
50 |
134 | 51 if (n->right != NULL) { |
147 | 52 descendTree(n->right, d+1); |
79
52da06c3f050
add printTree.cc & fix Makefile
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
53 } |
52da06c3f050
add printTree.cc & fix Makefile
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
54 } |
52da06c3f050
add printTree.cc & fix Makefile
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
55 |
52da06c3f050
add printTree.cc & fix Makefile
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
56 void printTree(NodePtr n) { |
52da06c3f050
add printTree.cc & fix Makefile
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
57 puts("---Print Node----"); |
90
d139af3bbd67
remove static variable in printTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
89
diff
changeset
|
58 int d = 0; |
d139af3bbd67
remove static variable in printTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
89
diff
changeset
|
59 descendTree(n,d); |
79
52da06c3f050
add printTree.cc & fix Makefile
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
60 puts("-----------------"); |
52da06c3f050
add printTree.cc & fix Makefile
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
61 } |