Re: Artikel Debian

So, ist es ganz richtig, die IF-Label müssen dann kommen, wenn die Alternative besteht

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define X   1024
#define Y   1024
#define END -1

char statechar [Y][X];
char statelevel [Y][X];
int x;
int y;

int initstates () {
    int k, l;

    for (k = 0;  k < Y;  k++) {
        for (l = 0;  l < X;  l++) {
            statechar [k][l] = ' ';
        }
    }

}

int jx = 0;

char text [] = "abcd";

//char expr [] = "abc*de[fasd,asddsr]qdsda*ghijk";
//char expr [] = "[*([[[([a,[[[p,q*],ca],[d,*(ead)]]]f*(mmm(nnn)mm)),a],asd],semdu]),*poller]";
//char expr [] = "[*([[[([a,[[[p,*(q)],ca],[d,*(ead)]]]f*(mmm(nnn)mm)),a],asd],semdu]),*poller]";
//char expr [] = "*(mmm(nnn)mm)";
char expr [] = "[a,*(a)*(a)*(a(bcd))(ab)]";
//char expr [] = "abcd";
int i = 0;

char gettoken () {
    return expr [i++];
}
void tokenback () {
    i--;
}

/*
aaaa
aaaaaa
aaaaaaa
aaaaaaaa()
*/

int stream (int);
int followed (int);
int compound (int);
int or_operator (int);
int repeat_operator (int);

int or_operator (int l) {
    int ch;
    if ((ch = gettoken ()) == '[') {
        or_operator (l+1);

        if (gettoken () != ',') {
            fprintf (stderr, "Komma vergessen");
            exit (1);
        }
        statechar [y][x] = '\$';
        statelevel [y][x] = l;
        x++;
        y++;
        or_operator (l+1);
        if ((ch = gettoken ()) != ']') {
            fprintf (stderr, "Klammer vergessen ]");
            exit (1);
        }
        repeat_operator (l);
    }
    else {
        tokenback ();
        repeat_operator (l);
    }

}


int repeat_operator (int l) {
    if (gettoken () == '*') {
        statechar [y][x] = '#';
        statelevel [y][x] = l;
        x++;
        stream (l);
    }
    else {
        tokenback ();
        stream (l);
    }

}

int stream (int l) {
    int r = 0;
    r = compound (l);
    r |= followed (l);
    if (r) {
        or_operator(l);
    }
}

int followed (int l) {
    int ch = gettoken ();
    int st, xtmp;
    if ((ch >= 'a') \&amp;\&amp; (ch <= 'z')) {
        statechar [y][x] = ch;
        statelevel [y][x] = l;
        x = x+1;
        or_operator (l);
        return 1;
    }
    else {
        tokenback ();
        return 0;
    }
}

int compound (int l) {
    int ch;
    if (gettoken () == '(') {
        statechar [y][x] = '@';
        statelevel [y][x] = l;
        x++;
        y++;
        or_operator (l+1);
        if ((ch = gettoken ()) != ')') {
            fprintf (stderr, "fehler klammer vergessen %c %in", expr [i], i);
            exit (1);
        }
        return 1;
    }
    else {
        tokenback ();
        return 0;
    }
}

void automat () {
    int k;
    for (k = 0;  k < strlen (text);  k++) {
        if (statechar [0][k] == text[k])
            printf ("fits %s", text +k);
        if (statechar [0][k] == '#');
    }
}

int main (void) {
    int k, l;
    initstates ();
    or_operator (0);

    for (l = 0;  l <= y;  l++) {
        for (k = 0;  k <= x;  k++)
            printf ("%2c%2i ", statechar [l][k], statelevel[l][k]);
        printf ("n");
    }
    automat ();
}