view regexParser/node.cc @ 188:109d22faf7b5 pairPro

remove errors and warnings
author Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
date Fri, 25 Dec 2015 02:57:21 +0900
parents ef798db705e9
children 3e8e5780ad4a
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("(%ld)\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("(%d)\n",n->stateNum);
    } 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("-----------------");
}