%{ /* * Copyright (c) 2002 by Laboratoire Spécification et Vérification (LSV), * CNRS UMR 8643 & ENS Cachan. * Written by Jean Goubault-Larrecq. Not derived from licensed software. * * Permission is granted to anyone to use this software for any * purpose on any computer system, and to redistribute it freely, * subject to the following restrictions: * * 1. Neither the author nor its employer is responsible for the consequences of use of * this software, no matter how awful, even if they arise * from defects in it. * * 2. The origin of this software must not be misrepresented, either * by explicit claim or by omission. * * 3. Altered versions must be plainly marked as such, and must not * be misrepresented as being the original software. * * 4. This software is restricted to non-commercial use only. Commercial * use is subject to a specific license, obtainable from LSV. * This was developed as part of the EVA project; as such, access * to this software by partners of the RNTL EVA Project (Trusted * Logic S.A., Verimag) is defined by the intellectual property * agreement signed as part of this project. */ /* Patch parser file. */ #include #include typedef enum { lngs, ints, chrs, strgs } type; char *ctype[] = {"int", "short", "char", "char * "}; #define NTABLES 32 #define RES_START 256 #define MAXBUF 80 char name[MAXBUF]; int n = 0; int size; int nentries; struct resource { char name[MAXBUF]; char size[MAXBUF]; type type; } resources[NTABLES]; void put(s) char *s; { fputs(s,stdout); } %} SPACE [\ \t] DIGIT [0-9] LETTER [A-Za-z_] %x table %x keyword %option noyywrap %% static{SPACE}const { /* this is the start of a table */ nentries = 0; BEGIN(table); } \"[^\"\n]*\" | . | \n { ECHO; } short({SPACE}+int)? { resources[n].type = ints; }
int |
long({SPACE}+int)? { resources[n].type = lngs; }
(unsigned{SPACE}+)?char { resources[n].type = chrs; }
char{SPACE}*\*{SPACE}*(const)? { resources[n].type = strgs; }
{LETTER}+{DIGIT}*\[{DIGIT}*\] { char *s,*t; for (s = resources[n].name, t = yytext; (*s++ = *t++)!='['; ); s[-1] = '\0'; for (s = resources[n].size; (*s++ = *t++)!=']'; ); s[-1] = '\0'; }
= { /* time to output the tables! */ /* Correct a bug: the table yytname[] is inside an "#if YYDEBUG!=0", together with yyrline[]. However, we also need yytname[] when YYDEBUG==0 but YYERROR_VERBOSE is defined. */ if (strcmp(resources[n].name,"yytname")==0) { /* so, instead we close the "#if YYDEBUG!=0", and insert what's needed: */ fputs("\n#define WANT_YYTNAME\n#endif\n\n#ifndef WANT_YYTNAME\n#ifdef YYERROR_VERBOSE\n#define WANT_YYTNAME\n#endif\n#endif\n\n#ifdef WANT_YYTNAME\n",stdout); } /* now, back to printing the tables: */ fprintf(stdout,"\nstatic %s %s[%s] =\n", ctype[resources[n].type],resources[n].name,resources[n].size); }
\}; { /* this is the end of a table */ ECHO; fprintf(stdout,"\n#define %s_SIZE %d\n",resources[n].name,nentries); n++; BEGIN(INITIAL); }
\" { nentries++; put(yytext); BEGIN(keyword); }
{DIGIT}+ { nentries++; put(yytext); }
. |
\n { put(yytext); } [kK]w_ { /* signals a description rather than a proper keyword */ } _ { put(" "); } open_paren { put("("); } close_paren { put(")"); } open_bracket { put("["); } close_bracket { put("]"); } open_brace { put("{"); } close_brace { put("}"); } open_angle { put("<"); } close_angle { put(">"); } comma { put(","); } colon { put(":"); } semi { put(";"); } kw_identifier { put(yytext+3); } \" { put(yytext); BEGIN(table); } \'[^\'\"\n]\' { fputc(yytext[1], stdout); } @{DIGIT}+ | . | \n { put(yytext); } %% main() { yylex(); exit(0); }