Mercurial > hg > Members > masakoha > testcode
annotate regexParser/node.cc @ 167:3bf2c6d6d53e pairPro
move regexparser dir
author | masa |
---|---|
date | Sat, 19 Dec 2015 15:38:45 +0900 |
parents | c/regexParser/node.cc@84d32375383a |
children | b9e913030a47 |
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> |
117
166136236891
add header files
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
116
diff
changeset
|
2 #include "node.h" |
112
ec485345daf9
some function use static
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
110
diff
changeset
|
3 |
139
6c258910cacb
remove some warning and error
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
135
diff
changeset
|
4 static void printCharacterClass(CharClassPtr cc, long nodeNumber,int d) { |
135 | 5 if (cc->type == 'r') { |
147 | 6 if (cc->left) { |
7 printCharacterClass(cc->left,nodeNumber,d+1); | |
8 } | |
135 | 9 printf("%*c",d*4, ' '); |
145
50217a0545e8
fix charClass()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
144
diff
changeset
|
10 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
|
11 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
|
12 if (range.next != NULL) { |
50217a0545e8
fix charClass()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
144
diff
changeset
|
13 range = *range.next; |
50217a0545e8
fix charClass()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
144
diff
changeset
|
14 } else { |
50217a0545e8
fix charClass()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
144
diff
changeset
|
15 break; |
50217a0545e8
fix charClass()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
144
diff
changeset
|
16 } |
135 | 17 } |
139
6c258910cacb
remove some warning and error
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
135
diff
changeset
|
18 printf("(%lu)\n",nodeNumber); |
147 | 19 if (cc->right) { |
20 printCharacterClass(cc->right,nodeNumber,d+1); | |
21 } | |
135 | 22 } |
23 } | |
24 | |
112
ec485345daf9
some function use static
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
110
diff
changeset
|
25 static void descendTree(NodePtr n, int d) { |
134 | 26 if (n->left != NULL) { |
147 | 27 descendTree(n->left, d+1); |
79
52da06c3f050
add printTree.cc & fix Makefile
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
28 } |
135 | 29 if (n->tokenType == 'a') { |
131 | 30 printf("%*c",d*4, ' '); |
144
d8a4922eceae
remove some errors (not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
139
diff
changeset
|
31 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
|
32 putchar(n->cc->cond.w.word[i]); |
131 | 33 } |
34 printf("(%lu)\n",n->nodeNumber); | |
135 | 35 } else if (n->tokenType == 'c') { |
139
6c258910cacb
remove some warning and error
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
135
diff
changeset
|
36 printCharacterClass(n->cc,n->nodeNumber,d); |
135 | 37 } else { |
38 printf("%*c%c(%lu)\n",d*4, ' ',n->tokenType,n->nodeNumber); | |
130
7925e9abb078
add or flag
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
120
diff
changeset
|
39 } |
89
50a146c05192
add NodeNumber in Regex Parser tree
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
79
diff
changeset
|
40 |
134 | 41 if (n->right != NULL) { |
147 | 42 descendTree(n->right, d+1); |
79
52da06c3f050
add printTree.cc & fix Makefile
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
43 } |
52da06c3f050
add printTree.cc & fix Makefile
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
44 } |
52da06c3f050
add printTree.cc & fix Makefile
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
45 |
52da06c3f050
add printTree.cc & fix Makefile
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
46 void printTree(NodePtr n) { |
52da06c3f050
add printTree.cc & fix Makefile
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
47 puts("---Print Node----"); |
90
d139af3bbd67
remove static variable in printTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
89
diff
changeset
|
48 int d = 0; |
d139af3bbd67
remove static variable in printTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
89
diff
changeset
|
49 descendTree(n,d); |
79
52da06c3f050
add printTree.cc & fix Makefile
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
50 puts("-----------------"); |
52da06c3f050
add printTree.cc & fix Makefile
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
51 } |