#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 expr [] = "abc*de[fasd,asddsr]qdsda*ghijk"; //char expr [] = "[a,[[[p,q],ca],[d,e]]]f*(mmm(nnn)mm)"; char expr [] = "[a,[[[p,q],ca],[d,e]]]f*(mmm(nnn)mm)"; 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) { if (gettoken () == '[') { or_operator (l+1); if (gettoken () != ',') { fprintf (stderr, "Komma vergessen"); exit (1); } y++; or_operator (l+1); if (gettoken () != ']') { fprintf (stderr, "Klammer vergessen ]"); exit (1); } repeat_operator (l); } else { tokenback (); repeat_operator (l); } } int repeat_operator (int l) { if (gettoken () == '*') { stream (l+1); statechar [y][x] = '#'; statelevel [y][x] = l; } else { tokenback (); stream (l); } } int stream (int l) { compound (l); followed (l); } int followed (int l) { int ch = gettoken (); int st, xtmp; if ((ch >= 'a') \&\& (ch <= 'z')) { statechar [y][x] = ch; statelevel [y][x] = l; x = x+1; or_operator (l); } else tokenback (); } int compound (int l) { if (gettoken () == '(') { y++; or_operator (l+1); if (gettoken () != ')') { fprintf (stderr, "fehler klammer vergessen %c %in", expr [i], i); exit (1); } } else tokenback (); } int main (void) { int k, l; initstates (); or_operator (0); for (l = 0; l < 12; l++) { for (k = 0; k < 12; k++) printf ("(%2c,%2i) ", statechar [l][k], statelevel[l][k]); printf ("n"); } }