#include <stdio.h> #include <stdlib.h> #include <string.h> #define X 1024 #define Y 1024 #define END -1 int state1 [Y][X][2]; int state2 [Y][X][2]; int statechar [Y][X]; int x; int y; int states () { int k, l; for (k = 0; k < Y; k++) for (l = 0; l < X; l++) state1 [k][l][0] = state2 [k][l][0] = state1 [k][l][1] = state2 [k][l][1] = statechar [k][l] = END; } int jx = 0; //char expr [] = "abc*de[fasd,asddsr]qdsda*ghijk"; char expr [] = "[a,[d,e]]efghijk"; int i = 0; char gettoken () { return expr [i++]; } void tokenback () { i--; } /* aaaa aaaaaa aaaaaaa aaaaaaaa() */ int stream (); int followed (); int compound (); int or_operator (); int repeat_operator (); int or_operator () { if (gettoken () == '[') { state1 [y][x][0] = x+1; state1 [y][x][1] = y+1; x++; y++; or_operator (); if (gettoken () != ',') { fprintf (stderr, "Komma vergessen"); exit (1); } state1 [y][x][0] = x+1; state1 [y][x][1] = y+1; x++; y++; or_operator (); if (gettoken () != ']') { fprintf (stderr, "Klammer vergessen ]"); exit (1); } repeat_operator (); } else { tokenback (); repeat_operator (); } } int repeat_operator () { if (gettoken () == '*') { stream (); } else { tokenback (); stream (); } } int stream () { compound (); followed (); } int followed () { int ch = gettoken (); int st, xtmp; if ((ch >= 'a') \&\& (ch <= 'z')) { printf ("%c ", ch); state1 [y][x][0] = y; state1 [y][x][1] = x+1; state2 [y][x][0] = y; state2 [y][x][1] = x+1; statechar [y][x] = ch; x = x+1; or_operator (); printf ("%in", x); } else tokenback (); } int compound () { if (gettoken () == '(') { or_operator (); if (gettoken () != ')') { fprintf (stderr, "fehler klammer vergessen %c %in", expr [i], i); exit (1); } } else tokenback (); } int main (void) { int k, l; or_operator (0); for (k = 0; k < 10; k++) { printf ("state1[0][%i][x] = %i, state1[0][%i][y] = %i ", k, state1[0][k][0], k, state1[0][k][1]); printf ("state2[0][%i][x] = %i, state2[0][%i][y] = %i ", k, state2[0][k][0], k, state2[0][k][1]); printf ("statechar[0][%i] = %cn", k, statechar[0][k]); } for (l = 0; l < 10; l++) { for (k = 0; k < 10; k++) printf ("(%2i,%2i,%2i,%2i) ", state1[l][k][0], state1[l][k][1], state2[l][k][0], state2[l][k][1]); printf ("n"); } }