Mercurial > hg > Members > masakoha > testcode
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/regexParser/node.cc Sat Dec 19 15:38:45 2015 +0900 @@ -0,0 +1,51 @@ +#include <stdio.h> +#include "node.h" + +static void printCharacterClass(CharClassPtr cc, long nodeNumber,int d) { + if (cc->type == 'r') { + if (cc->left) { + printCharacterClass(cc->left,nodeNumber,d+1); + } + printf("%*c",d*4, ' '); + for (RangeList range = cc->cond.range; range.begin != 0;) { + printf("[%c-%c] ",(unsigned char)range.begin,(unsigned char)range.end); + if (range.next != NULL) { + range = *range.next; + } else { + break; + } + } + printf("(%lu)\n",nodeNumber); + if (cc->right) { + printCharacterClass(cc->right,nodeNumber,d+1); + } + } +} + +static void descendTree(NodePtr n, int d) { + if (n->left != NULL) { + descendTree(n->left, d+1); + } + if (n->tokenType == 'a') { + printf("%*c",d*4, ' '); + for (int i = 0; i < n->cc->cond.w.length; i++) { + putchar(n->cc->cond.w.word[i]); + } + printf("(%lu)\n",n->nodeNumber); + } else if (n->tokenType == 'c') { + printCharacterClass(n->cc,n->nodeNumber,d); + } else { + printf("%*c%c(%lu)\n",d*4, ' ',n->tokenType,n->nodeNumber); + } + + if (n->right != NULL) { + descendTree(n->right, d+1); + } +} + +void printTree(NodePtr n) { + puts("---Print Node----"); + int d = 0; + descendTree(n,d); + puts("-----------------"); +}