%{ /* * lexer.l * * flex lexical analyzer for boxes configuration files * * Thomas Jensen * Date created: March 15, 1999 (Monday, 17:16h) */ /* #define DEBUG */ #include #include "boxes.h" #include "y.tab.h" int yylineno = 1; %} %x SAMPLE1 %x SAMPLE2 %s SHAPES %s OFFSETS %s ELASTIC %% [\r\t ]+ /* ignore whitespace */ \n yylineno++; #[^#].*$ { /* ignore comments */ #ifdef DEBUG fprintf (stderr, "\nCOMMENT: %s", yytext+1); #endif } \"[^"\n]*$ { yyerror ("Unterminated String at %s", yytext); exit (EXIT_FAILURE); } \"[^"\n]*\" { int bidx = yyleng-2; /* backslash index */ while (yytext[bidx] == '\\') bidx--; if ((yyleng-2-bidx) % 2) { yyless (yyleng-1); /* give back last quote */ yymore(); /* append next string */ } else { for (bidx=0; bidx\{ { #ifdef DEBUG fprintf (stderr, "\n SYMBOL: \'%c\' -- STATE SAMPLE2", yytext[0]); #endif BEGIN SAMPLE2; return yytext[0]; } [^{]+ { yyerror ("Syntax Error at %s", yytext); exit (EXIT_FAILURE); } \n { ++yylineno; if (yyleng > 1) yymore(); } \} { int bidx = yyleng-2; /* backslash index */ if (bidx >= 0) { while (bidx >= 0 && yytext[bidx] == '\\') bidx--; if ((yyleng-2-bidx) % 2) { /* odd number of backslashes */ yymore(); /* append next string */ } else { yyless (yyleng-1); /* have him recognize '}' symbol */ for (bidx=yyleng-1; yytext[bidx]=='\n'; --bidx) { yytext[bidx] = '\0'; /* remove trailing newlines */ --yyleng; } for (bidx=0; bidx. { yymore(); } Offsets { #ifdef DEBUG fprintf (stderr, "\nYOFFSET: %s -- STATE OFFSETS", yytext); #endif BEGIN OFFSETS; return YOFFSETS; } elastic { #ifdef DEBUG fprintf (stderr, "\nYELASTC: %s -- STATE ELASTIC", yytext); #endif BEGIN ELASTIC; return YELASTIC; } Shapes { #ifdef DEBUG fprintf (stderr, "\nYSHAPES: %s -- STATE SHAPES", yytext); #endif BEGIN SHAPES; return YSHAPES; } nw-nnw { yylval.offset = NW_NNW; return OFFSET; } nnw-n { yylval.offset = NNW_N; return OFFSET; } n-nne { yylval.offset = N_NNE; return OFFSET; } nne-ne { yylval.offset = NNE_NE; return OFFSET; } ne-ene { yylval.offset = NE_ENE; return OFFSET; } ene-e { yylval.offset = ENE_E; return OFFSET; } e-ese { yylval.offset = E_ESE; return OFFSET; } ese-se { yylval.offset = ESE_SE; return OFFSET; } se-sse { yylval.offset = SE_SSE; return OFFSET; } sse-s { yylval.offset = SSE_S; return OFFSET; } s-ssw { yylval.offset = S_SSW; return OFFSET; } ssw-sw { yylval.offset = SSW_SW; return OFFSET; } sw-wsw { yylval.offset = SW_WSW; return OFFSET; } wsw-w { yylval.offset = WSW_W; return OFFSET; } w-wnw { yylval.offset = W_WNW; return OFFSET; } wnw-nw { yylval.offset = WNW_NW; return OFFSET; } nw { yylval.shape = NW; return SHAPE; } nnw { yylval.shape = NNW; return SHAPE; } n { yylval.shape = N; return SHAPE; } nne { yylval.shape = NNE; return SHAPE; } ne { yylval.shape = NE; return SHAPE; } ene { yylval.shape = ENE; return SHAPE; } e { yylval.shape = E; return SHAPE; } ese { yylval.shape = ESE; return SHAPE; } se { yylval.shape = SE; return SHAPE; } sse { yylval.shape = SSE; return SHAPE; } s { yylval.shape = S; return SHAPE; } ssw { yylval.shape = SSW; return SHAPE; } sw { yylval.shape = SW; return SHAPE; } wsw { yylval.shape = WSW; return SHAPE; } w { yylval.shape = W; return SHAPE; } wnw { yylval.shape = WNW; return SHAPE; } \) { #ifdef DEBUG fprintf (stderr, "\n SYMBOL: \'%c\' -- STATE INITIAL", yytext[0]); #endif BEGIN INITIAL; return yytext[0]; } \} { #ifdef DEBUG fprintf (stderr, "\n SYMBOL: \'%c\' -- STATE INITIAL", yytext[0]); #endif BEGIN INITIAL; return yytext[0]; } BOX|revision|author|created|revdate|END { /* * general key words followed by a string */ #ifdef DEBUG fprintf (stderr, "\nKEYWORD: %s", yytext); #endif yylval.s = (char *) strdup (yytext); return KEYWORD; } [a-zA-ZäöüÄÖÜ][a-zA-Z0-9\-_üäöÜÄÖß]* { #ifdef DEBUG fprintf (stderr, "\n WORD: %s", yytext); #endif yylval.s = (char *) strdup (yytext); return WORD; } [,(){}] { #ifdef DEBUG fprintf (stderr, "\n SYMBOL: \'%c\'", yytext[0]); #endif return yytext[0]; } \-?[0-9]+ { #ifdef DEBUG fprintf (stderr, "\n NUMBER: %s", yytext); #endif yylval.num = atoi (yytext); return NUMBER; } . { yyerror ("Unrecognized input at %s", yytext); exit (EXIT_FAILURE); } %% /*EOF*/ /* vim: set cindent sw=4: */