Mercurial > hg > Members > masakoha > testcode
view regexParser/node.cc @ 309:058c87665213
small fix
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 08 Feb 2016 18:04:28 +0900 |
parents | 3e78631a6222 |
children |
line wrap: on
line source
#include <stdio.h> #include "regexParser.h" #include "node.h" static void printCharClassWord(CharClassPtr cc) { for (int i = 0; i < cc->cond.w.length; i++) { putchar(cc->cond.w.word[i]); } } void printCharacterClass(CharClassPtr cc, long nodeNumber,int d) { if (!cc) return; if (cc->left) { printCharacterClass(cc->left,nodeNumber,d+1); } printf("%*c",d*4, ' '); if (cc->cond.w.word) { printCharClassWord(cc); } else { RangeList range = cc->cond.range; printf("[%c-%c] ",(unsigned char)range.begin,(unsigned char)range.end); } printf("(0x%lx)\n",cc->nextState.bitContainer); 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, ' '); printCharClassWord(n->cc); if (n->state && n->nextState) { printf("(0x%lx)->(0x%lx)\n",n->state->bitState.bitContainer,n->nextState->bitState.bitContainer); } else if (n->state) { printf("(0x%lx)\n",n->state->bitState.bitContainer); } else { printf("\n"); } } 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("-----------------"); }