david@work:~\$ ./a.out ( a) ( ) ( ) ( e) ( f) ( g) ( h) ( i) ( j) ( k) ( ) ( d) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( e) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) david@work:~\$
#include <stdio.h> #include <stdlib.h> #include <string.h> #define X 1024 #define Y 1024 #define END -1 char statechar [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,[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 () == '[') { or_operator (); if (gettoken () != ',') { fprintf (stderr, "Komma vergessen"); exit (1); } y++; or_operator (); y--; 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')) { statechar [y][x] = ch; x = x+1; or_operator (); } 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; initstates (); or_operator (0); for (l = 0; l < 10; l++) { for (k = 0; k < 10; k++) printf ("(%2c) ", statechar [l][k]); printf ("n"); } }