Mercurial > hg > Applications > Grep
view regexParser/node.cc @ 212:b0ae5273925c
implement allocateCCState()
author | Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 28 Dec 2015 16:42:02 +0900 |
parents | b7b8f0c03fe3 |
children | a94f57af1600 |
line wrap: on
line source
#include <stdio.h> #include "regexParser.h" #include "node.h" void printCharacterClass(CharClassPtr cc, long nodeNumber,int d) { if (!cc) return; if (cc->type == 'a' || 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("(%d)\n",cc->stateNum); if (cc->right) { printCharacterClass(cc->right,nodeNumber,d+1); } } } 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("(%ld)\n",n->state->bitState.bitContainer); } else if (n->tokenType == 'c') { printCharacterClass(n->cc,n->stateNum,d); } else if (n->tokenType == 'a') { printf("%*c%c(%d)\n",d*4, ' ',n->tokenType,n->stateNum); } 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("-----------------"); }