%{ /* * File: lexer.l * Date created: March 15, 1999 (Monday, 17:16h) * Author: Thomas Jensen * tsjensen@stud.informatik.uni-erlangen.de * Version: $Id: lexer.l,v 1.10 1999/06/28 12:17:46 tsjensen Exp tsjensen $ * Language: lex (ANSI C) * Purpose: flex lexical analyzer for boxes configuration files * Remarks: --- * * Revision History: * * $Log: lexer.l,v $ * Revision 1.10 1999/06/28 12:17:46 tsjensen * Added tokens YBOX and YEND (thus, BOX and END are no longer YKEYWORDs) * Added #define FILE_LEXER_L around #include boxes.h to please compiler * * Revision 1.9 1999/06/22 12:00:05 tsjensen * Added #undef DEBUG, because DEBUGging is now activated in boxes.h * Added #include tools.h * * Revision 1.8 1999/06/20 14:17:58 tsjensen * Added "padding" keyword and recogintion of numbers (YNUMBER) * * Revision 1.7 1999/06/17 19:05:46 tsjensen * Bugfix: Sample block analysis didn't handle empty blocks * * Revision 1.6 1999/06/14 12:13:41 tsjensen * Added Reverse pattern * * Revision 1.5 1999/06/03 18:54:55 tsjensen * *** empty log message *** * * Revision 1.4 1999/04/09 13:31:13 tsjensen * Removed all code related to OFFSET blocks (obsolete) * * Revision 1.3 1999/04/04 16:11:39 tsjensen * Added indent keyword * Added Replace token * Some fiddling which will hopefully fix a line counting bug * * Revision 1.2 1999/03/30 09:42:51 tsjensen * Added rcs keywords and standard file header. * * Revision 1.1 1999/03/18 15:09:48 tsjensen * Initial revision * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ #include #include "shape.h" #define FILE_LEXER_L #include "boxes.h" #undef FILE_LEXER_L #include "tools.h" #include "y.tab.h" #define LEX_MAX_WARN 3 /* number of errors per design */ static const char rcsid_lexer_l[] = "$Id: lexer.l,v 1.10 1999/06/28 12:17:46 tsjensen Exp tsjensen $"; int yylineno = 1; int yyerrcnt = 0; %} %x SAMPLE1 %x SAMPLE2 %s SHAPES %s ELASTIC %% [\r\t ]+ /* ignore whitespace */ \n yylineno++; \"[^"\n]*$ { if (yyerrcnt++ < 5) yyerror ("Unterminated String at %s", yytext); return YUNREC; } \"[^"\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 LEXER_DEBUG fprintf (stderr, "\n SYMBOL: \'%c\' -- STATE SAMPLE2", yytext[0]); #endif BEGIN SAMPLE2; return yytext[0]; } [^{\n\t\r ]+ { if (yyerrcnt++ < 5) yyerror ("Syntax Error at \"%s\"", yytext); return YUNREC; } \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(); } Elastic { #ifdef LEXER_DEBUG fprintf (stderr, "\nYELASTC: %s -- STATE ELASTIC", yytext); #endif BEGIN ELASTIC; return YELASTIC; } Shapes { #ifdef LEXER_DEBUG fprintf (stderr, "\nYSHAPES: %s -- STATE SHAPES", yytext); #endif BEGIN SHAPES; return YSHAPES; } Box { #ifdef LEXER_DEBUG fprintf (stderr, "\nYBOX: %s", yytext); #endif yyerrcnt = 0; return YBOX; } Replace { return YREPLACE; } Reverse { return YREVERSE; } Padding { return YPADDING; } End { return YEND; } To { return YTO; } With { return YWITH; } Global { yylval.c = 'g'; return YRXPFLAG; } Once { yylval.c = 'o'; return YRXPFLAG; } 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 LEXER_DEBUG fprintf (stderr, "\n SYMBOL: \'%c\' -- STATE INITIAL", yytext[0]); #endif BEGIN INITIAL; return yytext[0]; } \} { #ifdef LEXER_DEBUG fprintf (stderr, "\n SYMBOL: \'%c\' -- STATE INITIAL", yytext[0]); #endif BEGIN INITIAL; return yytext[0]; } author|created|revision|revdate|indent { /* * general key words */ #ifdef LEXER_DEBUG fprintf (stderr, "\nKEYWORD: %s", yytext); #endif yylval.s = (char *) strdup (yytext); if (yylval.s == NULL) { perror (PROJECT); exit (EXIT_FAILURE); } return KEYWORD; } [a-zA-ZäöüÄÖÜ][a-zA-Z0-9\-_üäöÜÄÖß]* { #ifdef LEXER_DEBUG fprintf (stderr, "\n WORD: %s", yytext); #endif yylval.s = (char *) strdup (yytext); if (yylval.s == NULL) { perror (PROJECT); exit (EXIT_FAILURE); } return WORD; } [\+-]?[0-9]+ { #ifdef LEXER_DEBUG fprintf (stderr, "\nYNUMBER: %s", yytext); #endif yylval.num = atoi (yytext); return YNUMBER; } [,(){}] { #ifdef LEXER_DEBUG fprintf (stderr, "\n SYMBOL: \'%c\'", yytext[0]); #endif return yytext[0]; } #.*$ { /* ignore comments */ #ifdef LEXER_DEBUG fprintf (stderr, "\nCOMMENT: %s", yytext+1); #endif } . { if (yyerrcnt++ < LEX_MAX_WARN) yyerror ("Unrecognized input at %s", yytext); return YUNREC; } %% /*EOF*/ /* vim: set cindent sw=4: */