Implemented new SAMPLE block syntax

Replaced states SAMPLE1 and SAMPLE2 with new state SAMPLE - this is now
much simpler code
This commit is contained in:
Thomas Jensen 1999-08-16 16:28:03 +00:00
parent eefbebe467
commit 291158afc2

View File

@ -4,7 +4,7 @@
* Date created: March 15, 1999 (Monday, 17:16h) * Date created: March 15, 1999 (Monday, 17:16h)
* Author: Copyright (C) 1999 Thomas Jensen * Author: Copyright (C) 1999 Thomas Jensen
* tsjensen@stud.informatik.uni-erlangen.de * tsjensen@stud.informatik.uni-erlangen.de
* Version: $Id: lexer.l,v 1.12 1999/07/02 11:58:15 tsjensen Exp tsjensen $ * Version: $Id: lexer.l,v 1.13 1999/07/22 12:21:14 tsjensen Exp tsjensen $
* Language: lex (ANSI C) * Language: lex (ANSI C)
* Purpose: flex lexical analyzer for boxes configuration files * Purpose: flex lexical analyzer for boxes configuration files
* *
@ -24,6 +24,12 @@
* Revision History: * Revision History:
* *
* $Log: lexer.l,v $ * $Log: lexer.l,v $
* Revision 1.13 1999/07/22 12:21:14 tsjensen
* Added GNU GPL disclaimer
* Renamed y.tab.h include to parser.h (same file)
* Renamed parser.h include to lexer.h (same file)
* Added config.h include
*
* Revision 1.12 1999/07/02 11:58:15 tsjensen * Revision 1.12 1999/07/02 11:58:15 tsjensen
* Added begin_speedmode() which is called by parser.y * Added begin_speedmode() which is called by parser.y
* Added state SPEEDMODE for fast skipping of designs * Added state SPEEDMODE for fast skipping of designs
@ -45,7 +51,7 @@
* Added #include tools.h * Added #include tools.h
* *
* Revision 1.8 1999/06/20 14:17:58 tsjensen * Revision 1.8 1999/06/20 14:17:58 tsjensen
* Added "padding" keyword and recogintion of numbers (YNUMBER) * Added "padding" keyword and recognition of numbers (YNUMBER)
* *
* Revision 1.7 1999/06/17 19:05:46 tsjensen * Revision 1.7 1999/06/17 19:05:46 tsjensen
* Bugfix: Sample block analysis didn't handle empty blocks * Bugfix: Sample block analysis didn't handle empty blocks
@ -89,7 +95,7 @@
static const char rcsid_lexer_l[] = static const char rcsid_lexer_l[] =
"$Id: lexer.l,v 1.12 1999/07/02 11:58:15 tsjensen Exp tsjensen $"; "$Id: lexer.l,v 1.13 1999/07/22 12:21:14 tsjensen Exp tsjensen $";
int yylineno = 1; int yylineno = 1;
@ -100,8 +106,7 @@ int yyerrcnt = 0;
%option nounput %option nounput
%option noyywrap %option noyywrap
%x SAMPLE1 %x SAMPLE
%x SAMPLE2
%x SPEEDMODE %x SPEEDMODE
%s SHAPES %s SHAPES
%s ELASTIC %s ELASTIC
@ -112,9 +117,9 @@ PBOX Box
%% %%
<SAMPLE1,SHAPES,ELASTIC,INITIAL>[ \r\t] /* ignore whitespace */ <SHAPES,ELASTIC,INITIAL>[ \r\t] /* ignore whitespace */
<SAMPLE1,SHAPES,ELASTIC,INITIAL>\n ++yylineno; <SHAPES,ELASTIC,INITIAL>\n ++yylineno;
\"[^"\n]*$ { \"[^"\n]*$ {
if (yyerrcnt++ < 5) if (yyerrcnt++ < 5)
@ -157,80 +162,73 @@ PBOX Box
} }
} }
Sample { Sample {
#ifdef LEXER_DEBUG #ifdef LEXER_DEBUG
fprintf (stderr, "\n WORD: %s -- STATE SAMPLE1", yytext); fprintf (stderr, "\nYSAMPLE: %s -- STATE SAMPLE", yytext);
#endif #endif
BEGIN SAMPLE1; BEGIN SAMPLE;
return YSAMPLE; return YSAMPLE;
} }
<SAMPLE1>\{ {
#ifdef LEXER_DEBUG
fprintf (stderr, "\n SYMBOL: \'%c\' -- STATE SAMPLE2", yytext[0]);
#endif
BEGIN SAMPLE2;
return yytext[0];
}
<SAMPLE1>[^\{\n\r\t ]+ { <SAMPLE>\n {
if (yyerrcnt++ < 5)
yyerror ("Syntax Error at \"%s\"", yytext);
return YUNREC;
}
<SAMPLE2>\n {
++yylineno; ++yylineno;
if (yyleng > 1) if (yyleng > 1)
yymore(); yymore();
} }
<SAMPLE2>\} {
int bidx = yyleng-2; /* backslash index */
if (bidx >= 0) { <SAMPLE>^[ \t]*ends[ \t\r]*$ {
while (bidx >= 0 && yytext[bidx] == '\\') bidx--; char *p = yytext + yyleng -1;
size_t len; /* length of sample */
if ((yyleng-2-bidx) % 2) { /* odd number of backslashes */ while (*p == ' ' || *p == '\t' || *p == '\r')
yymore(); /* append next string */ --p; /* skip trailing whitespace */
} p -= 2; /* almost skip "ends" statement */
else { *p = '\0'; /* p now points to 'n' */
yyless (yyleng-1); /* have him recognize '}' symbol */ yylval.s = (char *) strdup (yytext);
if (yylval.s == NULL) {
perror (PROJECT);
exit (EXIT_FAILURE);
}
*p-- = 'n';
for (bidx=yyleng-1; yytext[bidx]=='\n'; --bidx) { len = p - yytext; /* yyless(n): push back all but the first n */
yytext[bidx] = '\0'; /* remove trailing newlines */ yyless (len); /* allow him to return YENDSAMPLE */
--yyleng;
} yylval.s[len] = '\n'; /* replace 'e' with newline */
for (bidx=0; bidx<yyleng-1; ++bidx) { btrim (yylval.s, &len);
if (yytext[bidx] == '\\') { if (len > 0) {
memmove (yytext+bidx, yytext+bidx+1, yyleng-bidx-1); strcat (yylval.s, "\n"); /* memory was allocated with strdup */
yytext[yyleng-1] = '\0'; #ifdef LEXER_DEBUG
--yyleng; /* inefficient */ fprintf (stderr, "\n STRING: \"%s\" -- STATE INITIAL", yylval.s);
} #endif
} BEGIN INITIAL;
BEGIN INITIAL; return STRING;
#ifdef LEXER_DEBUG
fprintf (stderr, "\n SAMPLE: %s -- STATE INITIAL", yytext);
#endif
yylval.s = (char *) strdup (yytext);
if (yylval.s == NULL) {
perror (PROJECT);
exit (EXIT_FAILURE);
}
return STRING;
}
} }
else { else {
if (yyerrcnt++ < 5) if (yyerrcnt++ < 5)
yyerror ("SAMPLE entry must not be empty"); yyerror ("SAMPLE block must not be empty");
BFREE (yylval.s);
return YUNREC; return YUNREC;
} }
} }
<SAMPLE2>. {
yymore(); <SAMPLE>. yymore();
ends[ \t\r]*$ {
#ifdef LEXER_DEBUG
fprintf (stderr, "\nYENDSAM: %s", yytext);
#endif
return YENDSAMPLE;
} }
Elastic { Elastic {
#ifdef LEXER_DEBUG #ifdef LEXER_DEBUG
fprintf (stderr, "\nYELASTC: %s -- STATE ELASTIC", yytext); fprintf (stderr, "\nYELASTC: %s -- STATE ELASTIC", yytext);