view regexParser/main.cc @ 231:d67649929e96

add grepWalk
author Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
date Tue, 19 Jan 2016 12:54:11 +0900
parents 399380ad95b7
children 1a34e702776a
line wrap: on
line source

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "regexParser.h"
#include "subsetConstruction.h"
#include "node.h"
#include "grepWalk.h"

int main(int argc, char **argv)
{
    bool generate = true;
    bool subset = false;
    bool generateSequentialSearch = false;

    RegexInfo ri;
    ri.stateNumber = 1;
    for (int i = 1; i < argc; i++) {
        if (strcmp(argv[i],"-regex") == 0) {
            ri.ptr = (unsigned char*)argv[i+1]; i++;
        } else if (strcmp(argv[i],"-noGeneration") == 0) {
            generate = false;
        } else if (strcmp(argv[i],"-subset") == 0) {
            subset = true;
        } else if (strcmp(argv[i],"-seq") == 0) {
            generateSequentialSearch = true;
        }
    }
    if (!ri.ptr) return 0;

    printf("regex : %s\n",ri.ptr);
    NodePtr n = regex(&ri);   // parse only
    printTree(n);

    TGValue tgv;
    if (generate && !subset)  {  // NFA generation
        tgv = generateTransitionList(n);
        printTree(n);
        printState(tgv.tg);
        if (generateSequentialSearch) {
            exportState(tgv.tg);
        }
    } else if (subset)  {
        tgv = generateTransitionList(n);
        SCValue scv = createSCValue(tgv);
        subsetConstruction(scv);   // Determinization
        printState(tgv.tg);
        if (generateSequentialSearch) {
            exportState(tgv.tg);
        }
    }

    grepWalk(tgv.tg);
    return 0;
}