Mercurial > hg > Members > masakoha > testcode
annotate regexParser/node.cc @ 309:058c87665213
small fix
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 08 Feb 2016 18:04:28 +0900 |
parents | 3e78631a6222 |
children |
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 |
309 | 5 static void printCharClassWord(CharClassPtr cc) { |
6 for (int i = 0; i < cc->cond.w.length; i++) { | |
7 putchar(cc->cond.w.word[i]); | |
8 } | |
9 } | |
10 | |
190
3e8e5780ad4a
change node::State to State
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
187
diff
changeset
|
11 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
|
12 if (!cc) return; |
309 | 13 if (cc->left) { |
14 printCharacterClass(cc->left,nodeNumber,d+1); | |
15 } | |
16 printf("%*c",d*4, ' '); | |
17 if (cc->cond.w.word) { | |
18 printCharClassWord(cc); | |
19 } else { | |
300 | 20 RangeList range = cc->cond.range; |
21 printf("[%c-%c] ",(unsigned char)range.begin,(unsigned char)range.end); | |
309 | 22 } |
23 printf("(0x%lx)\n",cc->nextState.bitContainer); | |
24 if (cc->right) { | |
25 printCharacterClass(cc->right,nodeNumber,d+1); | |
135 | 26 } |
27 } | |
28 | |
190
3e8e5780ad4a
change node::State to State
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
187
diff
changeset
|
29 void descendTree(NodePtr n, int d) { |
134 | 30 if (n->left != NULL) { |
147 | 31 descendTree(n->left, d+1); |
79
52da06c3f050
add printTree.cc & fix Makefile
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
32 } |
135 | 33 if (n->tokenType == 'a') { |
131 | 34 printf("%*c",d*4, ' '); |
309 | 35 printCharClassWord(n->cc); |
217 | 36 if (n->state && n->nextState) { |
309 | 37 printf("(0x%lx)->(0x%lx)\n",n->state->bitState.bitContainer,n->nextState->bitState.bitContainer); |
217 | 38 } else if (n->state) { |
309 | 39 printf("(0x%lx)\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 } |