home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
rtsi.com
/
2014.01.www.rtsi.com.tar
/
www.rtsi.com
/
OS9
/
TOP
/
USR
/
SRC
/
scpp.t.Z
/
scpp.t
/
lex.c
< prev
next >
Wrap
C/C++ Source or Header
|
2009-11-06
|
19KB
|
786 lines
#include <stdio.h>
#define U(x) (x)
#define NLSTATE yyprevious=YYNEWLINE
#define BEGIN yybgin = yysvec + 1 +
#define INITIAL 0
#define YYLERR yysvec
#define YYSTATE (yyestate-yysvec-1)
#define YYOPTIM 1
#define LEXDEBUG 1
#define YYLMAX 200
#define output(c) putc(c,yyout)
#define input() (((yytchar=yysptr>yysbuf?U(*--yysptr):getc(yyin))==13?(yylineno++,yytchar):yytchar)==EOF?0:yytchar)
#define unput(c) {yytchar= (c);if(yytchar=='\n')yylineno--;*yysptr++=yytchar;}
#define yymore() (yymorfg=1)
#define ECHO fprintf(yyout, "%s",yytext)
#define REJECT { nstr = yyreject(); goto yyfussy;}
int yyleng; extern char yytext[];
int yymorfg;
extern char *yysptr, yysbuf[];
int yytchar;
FILE *yyin = {stdin}, *yyout = {stdout};
extern int yylineno;
struct yysvf {
struct yywork *yystoff;
struct yysvf *yyother;
int *yystops;};
struct yysvf *yyestate;
extern struct yysvf yysvec[], *yybgin;
/*
* scpp - selective C preprocessor
* Lexical scanner
*
* Copyright (c) 1985 by
* Tektronix, Incorporated Beaverton, Oregon 97077
* All rights reserved.
*
* Permission is hereby granted for personal, non-commercial
* reproduction and use of this program, provided that this
* notice and all copyright notices are included in any copy.
*/
# include <stdio.h>
# undef input
# undef unput
# define input() (*nxtin == ATTN ? nxtc() : *nxtin++)
# define unput(c) unc(c)
# include "scpp.h"
# include "y.tab.h"
int lasttok = NL; /* used to detect ^# when lex can't */
# define yield(t) lasttok = t; questr(yytext, yyleng); return(t)
/*
* All input to higher levels of scpp is provided exclusively by this
* lexical analyzer, xxlex().
* This routine is called xxlex() rather than xxlex() because the "#if"
* expression parser uses a slightly different lexical analyzer (which
* calls xxlex()).
*/
#define YYNEWLINE 13
xxlex(){
int nstr; extern int yyprevious;
while((nstr = yylook()) >= 0)
yyfussy: switch(nstr){
case 0:
if(yywrap()) return(0); break;
case 1:
{yield(LT);}
break;
case 2:
{yield(LE);}
break;
case 3:
{yield(GT);}
break;
case 4:
{yield(GE);}
break;
case 5:
{yield(CM);}
break;
case 6:
{yield(DIV);}
break;
case 7:
{yield(MOD);}
break;
case 8:
{yield(PLUS);}
break;
case 9:
{yield(MINUS);}
break;
case 10:
{yield(LS);}
break;
case 11:
{yield(RS);}
break;
case 12:
{yield(MUL);}
break;
case 13:
{yield(EQ);}
break;
case 14:
{yield(NE);}
break;
case 15:
{yield(AND);}
break;
case 16:
{yield(OR);}
break;
case 17:
{yield(ER);}
break;
case 18:
{yield(ANDAND);}
break;
case 19:
{yield(OROR);}
break;
case 20:
{yield(QUEST);}
break;
case 21:
{yield(COLON);}
break;
case 22:
{yield(NOT);}
break;
case 23:
{yield(COMPL);}
break;
case 24:
{yield(LP);}
break;
case 25:
{yield(RP);}
break;
case 26:
{yield(CM);}
break;
case 27:
{yield(WHITE); /* whitespace */}
break;
case 28:
{/* escaped newline */
if (curfile->af_raw) {
curfile->af_line++;
}
yield(QNL);
}
break;
case 29:
{/* unescaped newline */
if (curfile->af_raw) {
curfile->af_line++;
}
yield(NL);
}
break;
case 30:
{yield(INT); /* hex constant */}
break;
case 31:
{yield(INT); /* decimal or octal constant */}
break;
case 32:
case 33:
case 34:
{yield(FLOAT); /* floating constant */}
break;
case 35:
{yield(IDENT); /* identifier */}
break;
case 36:
{yield(QUOTE);}
break;
case 37:
{yield(DQUOTE);}
break;
case 38:
{yield(BACKS);}
break;
case 39:
{yield(OPENC); /* start (open) comment */}
break;
case 40:
{yield(CLOSEC);/* finish (close) comment */}
break;
case 41:
{/*
* a control line if preceeded immediately by a newline,
* even if that newline was the result of macro interpretation.
*/
if (lasttok == NL) {
yield(POUNDLINE);
}
yield(OTHER);
}
break;
case 42:
{yield(OTHER);}
break;
case -1:
break;
default:
fprintf(yyout,"bad switch yylook %d",nstr);
} return(0); }
/* end of xxlex */
int yyvstop[] = {
0,
/* actions for state 2 */
42,
0,
/* actions for state 3 */
27,
42,
0,
/* actions for state 4 */
29,
0,
/* actions for state 5 */
22,
42,
0,
/* actions for state 6 */
37,
42,
0,
/* actions for state 7 */
41,
42,
0,
/* actions for state 8 */
7,
42,
0,
/* actions for state 9 */
15,
42,
0,
/* actions for state 10 */
36,
42,
0,
/* actions for state 11 */
24,
42,
0,
/* actions for state 12 */
25,
42,
0,
/* actions for state 13 */
12,
42,
0,
/* actions for state 14 */
8,
42,
0,
/* actions for state 15 */
5,
26,
42,
0,
/* actions for state 16 */
9,
42,
0,
/* actions for state 17 */
42,
0,
/* actions for state 18 */
6,
42,
0,
/* actions for state 19 */
31,
42,
0,
/* actions for state 20 */
31,
42,
0,
/* actions for state 21 */
21,
42,
0,
/* actions for state 22 */
1,
42,
0,
/* actions for state 23 */
42,
0,
/* actions for state 24 */
3,
42,
0,
/* actions for state 25 */
20,
42,
0,
/* actions for state 26 */
35,
42,
0,
/* actions for state 27 */
38,
42,
0,
/* actions for state 28 */
17,
42,
0,
/* actions for state 29 */
16,
42,
0,
/* actions for state 30 */
23,
42,
0,
/* actions for state 31 */
27,
0,
/* actions for state 32 */
14,
0,
/* actions for state 33 */
18,
0,
/* actions for state 34 */
40,
0,
/* actions for state 35 */
33,
0,
/* actions for state 36 */
39,
0,
/* actions for state 37 */
34,
0,
/* actions for state 38 */
31,
0,
/* actions for state 39 */
32,
0,
/* actions for state 40 */
31,
0,
/* actions for state 42 */
10,
0,
/* actions for state 43 */
2,
0,
/* actions for state 44 */
13,
0,
/* actions for state 45 */
4,
0,
/* actions for state 46 */
11,
0,
/* actions for state 47 */
35,
0,
/* actions for state 48 */
28,
0,
/* actions for state 49 */
19,
0,
/* actions for state 50 */
33,
0,
/* actions for state 51 */
34,
0,
/* actions for state 53 */
32,
0,
/* actions for state 54 */
30,
0,
/* actions for state 56 */
33,
0,
/* actions for state 58 */
34,
0,
/* actions for state 59 */
30,
0,
0};
#define YYTYPE char
struct yywork { YYTYPE verify, advance; } yycrank[] = {
0,0, 0,0, 1,3, 0,0,
0,0, 0,0, 0,0, 0,0,
0,0, 0,0, 1,4, 0,0,
0,0, 0,0, 1,5, 0,0,
0,0, 0,0, 0,0, 0,0,
0,0, 0,0, 0,0, 0,0,
0,0, 0,0, 0,0, 0,0,
0,0, 28,49, 0,0, 0,0,
0,0, 0,0, 1,6, 1,7,
1,8, 4,32, 1,9, 1,10,
1,11, 1,12, 1,13, 1,14,
1,15, 1,16, 1,17, 1,18,
1,19, 1,20, 1,21, 1,21,
1,21, 1,21, 1,21, 1,21,
1,21, 1,21, 1,21, 1,22,
4,32, 1,23, 1,24, 1,25,
1,26, 6,33, 1,27, 10,34,
14,35, 19,37, 1,27, 0,0,
1,27, 0,0, 0,0, 0,0,
0,0, 1,27, 18,36, 18,36,
18,36, 18,36, 18,36, 18,36,
18,36, 18,36, 18,36, 18,36,
23,43, 23,44, 24,45, 25,46,
25,47, 1,28, 0,0, 1,29,
53,54, 53,54, 53,54, 53,54,
53,54, 53,54, 53,54, 53,54,
53,54, 53,54, 0,0, 0,0,
20,38, 0,0, 20,39, 20,39,
20,39, 20,39, 20,39, 20,39,
20,39, 20,39, 20,39, 20,39,
0,0, 0,0, 36,51, 0,0,
0,0, 1,30, 0,0, 1,31,
2,6, 2,7, 2,8, 20,40,
2,9, 2,10, 2,11, 2,12,
2,13, 2,14, 20,41, 2,16,
2,17, 2,18, 2,19, 30,50,
2,21, 2,21, 2,21, 2,21,
2,21, 2,21, 2,21, 2,21,
2,21, 2,22, 36,51, 2,23,
2,24, 2,25, 2,26, 55,60,
0,0, 0,0, 0,0, 20,40,
0,0, 0,0, 0,0, 0,0,
0,0, 21,38, 20,41, 21,39,
21,39, 21,39, 21,39, 21,39,
21,39, 21,39, 21,39, 21,39,
21,39, 0,0, 20,42, 0,0,
0,0, 0,0, 0,0, 2,28,
0,0, 2,29, 0,0, 55,60,
21,40, 0,0, 0,0, 40,53,
0,0, 40,53, 0,0, 21,41,
40,54, 40,54, 40,54, 40,54,
40,54, 40,54, 40,54, 40,54,
40,54, 40,54, 0,0, 0,0,
0,0, 0,0, 0,0, 0,0,
0,0, 0,0, 0,0, 2,30,
0,0, 2,31, 0,0, 0,0,
21,40, 0,0, 0,0, 0,0,
0,0, 0,0, 0,0, 21,41,
27,48, 27,48, 27,48, 27,48,
27,48, 27,48, 27,48, 27,48,
27,48, 27,48, 0,0, 0,0,
0,0, 0,0, 0,0, 0,0,
0,0, 27,48, 27,48, 27,48,
27,48, 27,48, 27,48, 27,48,
27,48, 27,48, 27,48, 27,48,
27,48, 27,48, 27,48, 27,48,
27,48, 27,48, 27,48, 27,48,
27,48, 27,48, 27,48, 27,48,
27,48, 27,48, 27,48, 0,0,
0,0, 0,0, 0,0, 27,48,
0,0, 27,48, 27,48, 27,48,
27,48, 27,48, 27,48, 27,48,
27,48, 27,48, 27,48, 27,48,
27,48, 27,48, 27,48, 27,48,
27,48, 27,48, 27,48, 27,48,
27,48, 27,48, 27,48, 27,48,
27,48, 27,48, 27,48, 38,38,
38,38, 38,38, 38,38, 38,38,
38,38, 38,38, 38,38, 38,38,
38,38, 42,55, 42,55, 42,55,
42,55, 42,55, 42,55, 42,55,
42,55, 42,55, 42,55, 0,0,
38,52, 0,0, 0,0, 0,0,
0,0, 0,0, 42,55, 42,55,
42,55, 42,55, 42,55, 42,55,
51,56, 0,0, 51,56, 0,0,
0,0, 51,57, 51,57, 51,57,
51,57, 51,57, 51,57, 51,57,
51,57, 51,57, 51,57, 0,0,
0,0, 0,0, 0,0, 0,0,
38,52, 0,0, 0,0, 0,0,
0,0, 0,0, 42,55, 42,55,
42,55, 42,55, 42,55, 42,55,
52,58, 0,0, 52,58, 0,0,
0,0, 52,59, 52,59, 52,59,
52,59, 52,59, 52,59, 52,59,
52,59, 52,59, 52,59, 56,57,
56,57, 56,57, 56,57, 56,57,
56,57, 56,57, 56,57, 56,57,
56,57, 58,59, 58,59, 58,59,
58,59, 58,59, 58,59, 58,59,
58,59, 58,59, 58,59, 0,0,
0,0};
struct yysvf yysvec[] = {
0, 0, 0,
yycrank+-1, 0, 0, /* state 0 */
yycrank+-95, yysvec+1, 0, /* state 1 */
yycrank+0, 0, yyvstop+1, /* state 2 */
yycrank+28, 0, yyvstop+3, /* state 3 */
yycrank+0, 0, yyvstop+6, /* state 4 */
yycrank+4, 0, yyvstop+8, /* state 5 */
yycrank+0, 0, yyvstop+11, /* state 6 */
yycrank+0, 0, yyvstop+14, /* state 7 */
yycrank+0, 0, yyvstop+17, /* state 8 */
yycrank+29, 0, yyvstop+20, /* state 9 */
yycrank+0, 0, yyvstop+23, /* state 10 */
yycrank+0, 0, yyvstop+26, /* state 11 */
yycrank+0, 0, yyvstop+29, /* state 12 */
yycrank+21, 0, yyvstop+32, /* state 13 */
yycrank+0, 0, yyvstop+35, /* state 14 */
yycrank+0, 0, yyvstop+38, /* state 15 */
yycrank+0, 0, yyvstop+42, /* state 16 */
yycrank+30, 0, yyvstop+45, /* state 17 */
yycrank+27, 0, yyvstop+47, /* state 18 */
yycrank+62, 0, yyvstop+50, /* state 19 */
yycrank+123, 0, yyvstop+53, /* state 20 */
yycrank+0, 0, yyvstop+56, /* state 21 */
yycrank+28, 0, yyvstop+59, /* state 22 */
yycrank+29, 0, yyvstop+62, /* state 23 */
yycrank+30, 0, yyvstop+64, /* state 24 */
yycrank+0, 0, yyvstop+67, /* state 25 */
yycrank+184, 0, yyvstop+70, /* state 26 */
yycrank+16, 0, yyvstop+73, /* state 27 */
yycrank+0, 0, yyvstop+76, /* state 28 */
yycrank+19, 0, yyvstop+79, /* state 29 */
yycrank+0, 0, yyvstop+82, /* state 30 */
yycrank+0, yysvec+4, yyvstop+85, /* state 31 */
yycrank+0, 0, yyvstop+87, /* state 32 */
yycrank+0, 0, yyvstop+89, /* state 33 */
yycrank+0, 0, yyvstop+91, /* state 34 */
yycrank+53, yysvec+18, yyvstop+93, /* state 35 */
yycrank+0, 0, yyvstop+95, /* state 36 */
yycrank+259, 0, yyvstop+97, /* state 37 */
yycrank+0, yysvec+21, yyvstop+99, /* state 38 */
yycrank+152, 0, yyvstop+101, /* state 39 */
yycrank+0, 0, yyvstop+103, /* state 40 */
yycrank+269, 0, 0, /* state 41 */
yycrank+0, 0, yyvstop+105, /* state 42 */
yycrank+0, 0, yyvstop+107, /* state 43 */
yycrank+0, 0, yyvstop+109, /* state 44 */
yycrank+0, 0, yyvstop+111, /* state 45 */
yycrank+0, 0, yyvstop+113, /* state 46 */
yycrank+0, yysvec+27, yyvstop+115, /* state 47 */
yycrank+0, 0, yyvstop+117, /* state 48 */
yycrank+0, 0, yyvstop+119, /* state 49 */
yycrank+297, 0, yyvstop+121, /* state 50 */
yycrank+329, 0, yyvstop+123, /* state 51 */
yycrank+48, 0, 0, /* state 52 */
yycrank+0, yysvec+53, yyvstop+125, /* state 53 */
yycrank+83, yysvec+42, yyvstop+127, /* state 54 */
yycrank+339, 0, 0, /* state 55 */
yycrank+0, yysvec+56, yyvstop+129, /* state 56 */
yycrank+349, 0, 0, /* state 57 */
yycrank+0, yysvec+58, yyvstop+131, /* state 58 */
yycrank+0, 0, yyvstop+133, /* state 59 */
0, 0, 0};
struct yywork *yytop = yycrank+406;
struct yysvf *yybgin = yysvec+1;
char yymatch[] = {
00 ,01 ,01 ,01 ,01 ,01 ,01 ,01 ,
01 ,011 ,01 ,01 ,01 ,015 ,01 ,01 ,
01 ,01 ,01 ,01 ,01 ,01 ,01 ,01 ,
01 ,01 ,01 ,01 ,01 ,01 ,01 ,01 ,
011 ,01 ,01 ,01 ,01 ,01 ,01 ,01 ,
01 ,01 ,01 ,'+' ,01 ,'+' ,01 ,01 ,
'0' ,'0' ,'0' ,'0' ,'0' ,'0' ,'0' ,'0' ,
'0' ,'0' ,01 ,01 ,01 ,01 ,01 ,01 ,
01 ,'A' ,'A' ,'A' ,'A' ,'E' ,'A' ,'G' ,
'G' ,'G' ,'G' ,'G' ,'L' ,'G' ,'G' ,'G' ,
'G' ,'G' ,'G' ,'G' ,'G' ,'G' ,'G' ,'G' ,
'G' ,'G' ,'G' ,01 ,01 ,01 ,01 ,'G' ,
01 ,'A' ,'A' ,'A' ,'A' ,'E' ,'A' ,'G' ,
'G' ,'G' ,'G' ,'G' ,'L' ,'G' ,'G' ,'G' ,
'G' ,'G' ,'G' ,'G' ,'G' ,'G' ,'G' ,'G' ,
'G' ,'G' ,'G' ,01 ,01 ,01 ,01 ,01 ,
0};
char yyextra[] = {
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0};
/* @(#) 1.1 */
int yylineno =1;
# define YYU(x) x
# define NLSTATE yyprevious=YYNEWLINE
char yytext[YYLMAX];
struct yysvf *yylstate [YYLMAX], **yylsp, **yyolsp;
char yysbuf[YYLMAX];
char *yysptr = yysbuf;
int *yyfnd;
extern struct yysvf *yyestate;
int yyprevious = YYNEWLINE;
yylook(){
register struct yysvf *yystate, **lsp;
register struct yywork *yyt;
struct yysvf *yyz;
int yych, yyfirst;
struct yywork *yyr;
# ifdef LEXDEBUG
int debug;
# endif
char *yylastch;
/* start off machines */
# ifdef LEXDEBUG
debug = 0;
# endif
yyfirst=1;
if (!yymorfg)
yylastch = yytext;
else {
yymorfg=0;
yylastch = yytext+yyleng;
}
for(;;){
lsp = yylstate;
yyestate = yystate = yybgin;
if (yyprevious==YYNEWLINE) yystate++;
for (;;){
# ifdef LEXDEBUG
if(debug)fprintf(yyout,"state %d\n",yystate-yysvec-1);
# endif
yyt = yystate->yystoff;
if(yyt == yycrank && !yyfirst){ /* may not be any transitions */
yyz = yystate->yyother;
if(yyz == 0)break;
if(yyz->yystoff == yycrank)break;
}
*yylastch++ = yych = input();
yyfirst=0;
tryagain:
# ifdef LEXDEBUG
if(debug){
fprintf(yyout,"char ");
allprint(yych);
putchar('\n');
}
# endif
yyr = yyt;
if ( (int)yyt > (int)yycrank){
yyt = yyr + yych;
if (yyt <= yytop && yyt->verify+yysvec == yystate){
if(yyt->advance+yysvec == YYLERR) /* error transitions */
{unput(*--yylastch);break;}
*lsp++ = yystate = yyt->advance+yysvec;
goto contin;
}
}
# ifdef YYOPTIM
else if((int)yyt < (int)yycrank) { /* r < yycrank */
yyt = yyr = yycrank+(yycrank-yyt);
# ifdef LEXDEBUG
if(debug)fprintf(yyout,"compressed state\n");
# endif
yyt = yyt + yych;
if(yyt <= yytop && yyt->verify+yysvec == yystate){
if(yyt->advance+yysvec == YYLERR) /* error transitions */
{unput(*--yylastch);break;}
*lsp++ = yystate = yyt->advance+yysvec;
goto contin;
}
yyt = yyr + YYU(yymatch[yych]);
# ifdef LEXDEBUG
if(debug){
fprintf(yyout,"try fall back character ");
allprint(YYU(yymatch[yych]));
putchar('\n');
}
# endif
if(yyt <= yytop && yyt->verify+yysvec == yystate){
if(yyt->advance+yysvec == YYLERR) /* error transition */
{unput(*--yylastch);break;}
*lsp++ = yystate = yyt->advance+yysvec;
goto contin;
}
}
if ((yystate = yystate->yyother) && (yyt= yystate->yystoff) != yycrank){
# ifdef LEXDEBUG
if(debug)fprintf(yyout,"fall back to state %d\n",yystate-yysvec-1);
# endif
goto tryagain;
}
# endif
else
{unput(*--yylastch);break;}
contin:
# ifdef LEXDEBUG
if(debug){
fprintf(yyout,"state %d char ",yystate-yysvec-1);
allprint(yych);
putchar('\n');
}
# endif
;
}
# ifdef LEXDEBUG
if(debug){
fprintf(yyout,"stopped at %d with ",*(lsp-1)-yysvec-1);
allprint(yych);
putchar('\n');
}
# endif
while (lsp-- > yylstate){
*yylastch-- = 0;
if (*lsp != 0 && (yyfnd= (*lsp)->yystops) && *yyfnd > 0){
yyolsp = lsp;
if(yyextra[*yyfnd]){ /* must backup */
while(yyback((*lsp)->yystops,-*yyfnd) != 1 && lsp > yylstate){
lsp--;
unput(*yylastch--);
}
}
yyprevious = YYU(*yylastch);
yylsp = lsp;
yyleng = yylastch-yytext+1;
yytext[yyleng] = 0;
# ifdef LEXDEBUG
if(debug){
fprintf(yyout,"\nmatch ");
sprint(yytext);
fprintf(yyout," action %d\n",*yyfnd);
}
# endif
return(*yyfnd++);
}
unput(*yylastch);
}
if (yytext[0] == 0 /* && feof(yyin) */)
{
yysptr=yysbuf;
return(0);
}
yyprevious = yytext[0] = input();
if (yyprevious>0)
output(yyprevious);
yylastch=yytext;
# ifdef LEXDEBUG
if(debug)putchar('\n');
# endif
}
}
yyback(p, m)
int *p;
{
if (p==0) return(0);
while (*p)
{
if (*p++ == m)
return(1);
}
return(0);
}
/* the following are only used in the lex library */
yyinput(){
return(input());
}
yyoutput(c)
int c; {
output(c);
}
yyunput(c)
int c; {
unput(c);
}