Mercurial > hg > Members > masakoha > testcode
annotate regexParser/node.cc @ 187:ef798db705e9 pairPro
remove some warnings and errors(not working)
author | Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 24 Dec 2015 22:38:50 +0900 |
parents | b9e913030a47 |
children | 3e8e5780ad4a |
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 } |
187
ef798db705e9
remove some warnings and errors(not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
174
diff
changeset
|
18 printf("(%ld)\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 } |
187
ef798db705e9
remove some warnings and errors(not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
174
diff
changeset
|
34 printf("(%d)\n",n->stateNum); |
135 | 35 } 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
|
36 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
|
37 } 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
|
38 printf("%*c%c(%d)\n",d*4, ' ',n->tokenType,n->stateNum); |
135 | 39 } 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
|
40 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
|
41 } |
89
50a146c05192
add NodeNumber in Regex Parser tree
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
79
diff
changeset
|
42 |
134 | 43 if (n->right != NULL) { |
147 | 44 descendTree(n->right, d+1); |
79
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 } |
52da06c3f050
add printTree.cc & fix Makefile
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
47 |
52da06c3f050
add printTree.cc & fix Makefile
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
48 void printTree(NodePtr n) { |
52da06c3f050
add printTree.cc & fix Makefile
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
49 puts("---Print Node----"); |
90
d139af3bbd67
remove static variable in printTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
89
diff
changeset
|
50 int d = 0; |
d139af3bbd67
remove static variable in printTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
89
diff
changeset
|
51 descendTree(n,d); |
79
52da06c3f050
add printTree.cc & fix Makefile
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
52 puts("-----------------"); |
52da06c3f050
add printTree.cc & fix Makefile
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
53 } |