Mercurial > hg > Applications > Grep
view regexParser/node.cc @ 176:c092dd0e1ae0 pairPro
implement appendState() and serchState()
author | Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 23 Dec 2015 15:41:27 +0900 |
parents | b9e913030a47 |
children | ef798db705e9 |
line wrap: on
line source
#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 if (n->tokenType == 'a') { printf("%*c%c(%lu)\n",d*4, ' ',n->tokenType,n->nodeNumber); } else { printf("%*c%c\n",d*4, ' ',n->tokenType); } if (n->right != NULL) { descendTree(n->right, d+1); } } void printTree(NodePtr n) { puts("---Print Node----"); int d = 0; descendTree(n,d); puts("-----------------"); }