Mercurial > hg > Applications > Grep
comparison 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 |
comparison
equal
deleted
inserted
replaced
166:96854eba17e5 | 167:3bf2c6d6d53e |
---|---|
1 #include <stdio.h> | |
2 #include "node.h" | |
3 | |
4 static void printCharacterClass(CharClassPtr cc, long nodeNumber,int d) { | |
5 if (cc->type == 'r') { | |
6 if (cc->left) { | |
7 printCharacterClass(cc->left,nodeNumber,d+1); | |
8 } | |
9 printf("%*c",d*4, ' '); | |
10 for (RangeList range = cc->cond.range; range.begin != 0;) { | |
11 printf("[%c-%c] ",(unsigned char)range.begin,(unsigned char)range.end); | |
12 if (range.next != NULL) { | |
13 range = *range.next; | |
14 } else { | |
15 break; | |
16 } | |
17 } | |
18 printf("(%lu)\n",nodeNumber); | |
19 if (cc->right) { | |
20 printCharacterClass(cc->right,nodeNumber,d+1); | |
21 } | |
22 } | |
23 } | |
24 | |
25 static void descendTree(NodePtr n, int d) { | |
26 if (n->left != NULL) { | |
27 descendTree(n->left, d+1); | |
28 } | |
29 if (n->tokenType == 'a') { | |
30 printf("%*c",d*4, ' '); | |
31 for (int i = 0; i < n->cc->cond.w.length; i++) { | |
32 putchar(n->cc->cond.w.word[i]); | |
33 } | |
34 printf("(%lu)\n",n->nodeNumber); | |
35 } else if (n->tokenType == 'c') { | |
36 printCharacterClass(n->cc,n->nodeNumber,d); | |
37 } else { | |
38 printf("%*c%c(%lu)\n",d*4, ' ',n->tokenType,n->nodeNumber); | |
39 } | |
40 | |
41 if (n->right != NULL) { | |
42 descendTree(n->right, d+1); | |
43 } | |
44 } | |
45 | |
46 void printTree(NodePtr n) { | |
47 puts("---Print Node----"); | |
48 int d = 0; | |
49 descendTree(n,d); | |
50 puts("-----------------"); | |
51 } |