#include <string.h>

#include <malloc.h>

#include <stdio.h>

#include <ctype.h>


struct NFA;


typedef struct NFA_LIST { struct NFA_LIST* next; struct NFA* data; }   NFA_LIST;

typedef struct NFA {  struct NFA* next;struct  NFA_LIST* connect; char* data; }   NFA;


NFA_LIST* new_list() { NFA_LIST* nfa = (NFA_LIST *)malloc(sizeof(NFA_LIST)); nfa-> nfa- gt;next = 0; return nfa; }

NFA* new_nfa() { NFA* nfa = (NFA *)malloc(sizeof(NFA)); nfa-> nfa- gt;connect = 0; nfa->next = 0; return nfa; }

void next_list(NFA* l, NFA* d) 

{

    NFA_LIST* r = l->connect;

    if (r)

    {

        while (r->next)

            r = r->next;

        r = r->next = new_list();

    }

    else

        r = l->connect = new_list();

    r->>

}


static NFA* head;

static NFA* last;

static const char* set;

static char* str;


assoc_follow(ch) { return strchr("|()", ch); }


var()

{

    if ( *set == '(' )

    {

        *set++;

        NFA* store = last;

        if (last->connect || last->data) {

            last->next = new_nfa();

            last = last->next; 

        }

        follow();

        if ( *set == ')' )

            set++;

    }

    else

    {

        static char tmp[256];

        int top = 0;

        while ( !assoc_follow(*set) && *set ) 

            tmp[top++] = *set++;

        if (top == 0)

            return;

        tmp[top] = 0; 

        str = _strdup(tmp);

    }

}


follow_connecting() { 

    NFA* nfa = new_nfa();

    nfa->>

    next_list(last, nfa);

    str = 0; }

follow()

{

    var();

    while( *set == '|' )

    {

        *set++;

        follow_connecting();

var();

        follow_connecting();

    }


    if ( str ) {

        if (last->connect || last->data) {

            last->next = new_nfa();

            last = last->next; 

        }

        last->>

        str = 0;

    }

    if ( *set && *set != ')' )

        follow();

}


main()

{

    set =  "a(b|c)d";

    head = last = new_nfa();

    follow();

}


ㅇㅇ