Mercurial > hg > Applications > Grep
comparison c/regexParser/node.cc @ 135:e1a262ec75f0 pairPro
impl charclass
author | masa |
---|---|
date | Fri, 04 Dec 2015 19:07:10 +0900 |
parents | dbafc753078e |
children | 6c258910cacb |
comparison
equal
deleted
inserted
replaced
134:dbafc753078e | 135:e1a262ec75f0 |
---|---|
1 #include <stdio.h> | 1 #include <stdio.h> |
2 #include "node.h" | 2 #include "node.h" |
3 | |
4 static void printCharacterClass(CharClassPtr cc, int d) { | |
5 if (cc->type == 'r') { | |
6 printf("%*c",d*4, ' '); | |
7 for (RangeListPtr range = cc->cond->range; range; range = range->next) { | |
8 printf("%c-%c ",*range->begin,*range->end); | |
9 } | |
10 printf("\n"); | |
11 } | |
12 } | |
3 | 13 |
4 static void descendTree(NodePtr n, int d) { | 14 static void descendTree(NodePtr n, int d) { |
5 if (n->left != NULL) { | 15 if (n->left != NULL) { |
6 d++; | 16 d++; |
7 descendTree(n->left, d); | 17 descendTree(n->left, d); |
8 d--; | 18 d--; |
9 } | 19 } |
10 if (n->tokenType != 'a') { | 20 if (n->tokenType == 'a') { |
11 printf("%*c%c(%lu)\n",d*4, ' ',n->tokenType,n->nodeNumber); | |
12 } else { | |
13 printf("%*c",d*4, ' '); | 21 printf("%*c",d*4, ' '); |
14 for (int i = 0; i < n->cc->cond->w->length; i++) { | 22 for (int i = 0; i < n->cc->cond->w->length; i++) { |
15 putchar(n->cc->cond->w->word[i]); | 23 putchar(n->cc->cond->w->word[i]); |
16 } | 24 } |
17 printf("(%lu)\n",n->nodeNumber); | 25 printf("(%lu)\n",n->nodeNumber); |
26 } else if (n->tokenType == 'c') { | |
27 printCharacterClass(n->cc,d); | |
28 } else { | |
29 printf("%*c%c(%lu)\n",d*4, ' ',n->tokenType,n->nodeNumber); | |
18 } | 30 } |
19 | 31 |
20 if (n->right != NULL) { | 32 if (n->right != NULL) { |
21 d++; | 33 d++; |
22 descendTree(n->right, d); | 34 descendTree(n->right, d); |