home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Interactive Guide
/
c-cplusplus-interactive-guide.iso
/
c_ref
/
csource5
/
310_01
/
lexyy.c
< prev
next >
Wrap
Text File
|
1990-04-20
|
22KB
|
1,116 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 YYLMAX 200
# define output(c) putc(c,yyout)
# define input() (((yytchar=yysptr>yysbuf?U(*--yysptr):getc(yyin))==10?(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;
/*
Little Smalltalk lexical analyzer
*/
# include <math.h>
# include "primnum.h"
# undef input
# undef unput
double atof();
int linenum = 1;
# define YYNEWLINE 10
yylex(){
int nstr; extern int yyprevious;
while((nstr = yylook()) >= 0)
yyfussy: switch(nstr){
case 0:
if(yywrap()) return(0); break;
case 1:
{;}
break;
case 2:
{linenum++;}
break;
case 3:
{readcomment();}
break;
case 4:
{return(ASSIGN);}
break;
case 5:
{return(ASSIGN);}
break;
case 6:
{return(lexsave(CLASS));}
break;
case 7:
{yylval.p = selfvar; return(PSEUDO);}
break;
case 8:
{yylval.p = procvar; return(PSEUDO);}
break;
case 9:
{yylval.p = supervar; return(PSEUDO);}
break;
case 10:
{yylval.p = nilvar; return(PSEUDO);}
break;
case 11:
{yylval.p = truevar; return(PSEUDO);}
break;
case 12:
{yylval.p = falsevar; return(PSEUDO);}
break;
case 13:
{yylval.p = smallvar; return(PSEUDO);}
break;
case 14:
{yylval.i = yytext[1]; return(LITCHAR);}
break;
case 15:
{return(PS);}
break;
case 16:
{return(lexsave(LITFNUM));}
break;
case 17:
{yylval.i = atoi(yytext); return(LITNUM);}
break;
case 18:
{return(lexsave(LITFNUM));}
break;
case 19:
{char c; unput(c = input());
if (c == '\'') yymore();
else return(lexlstr());}
break;
case 20:
{return(varlex());}
break;
case 21:
{return(slexsave(COLONVAR));}
break;
case 22:
{return(slexsave(LITSYM));}
break;
case 23:
{return(lexsave(MINUS));}
break;
case 24:
{return(LP);}
break;
case 25:
{return(RP);}
break;
case 26:
{return(LB);}
break;
case 27:
{return(RB);}
break;
case 28:
{return(PERIOD);}
break;
case 29:
{return(lexsave(MBAR));}
break;
case 30:
{return(lexsave(MBAR));}
break;
case 31:
{return(lexsave(BAR));}
break;
case 32:
{return(lexsave(BAR));}
break;
case 33:
{return(SEMI);}
break;
case 34:
{return(lexsave(UPARROW));}
break;
case 35:
{return(lexsave(PE));}
break;
case 36:
{return(lexsave(BINARY));}
break;
case 37:
{return(PRIMITIVE);}
break;
case 38:
{yylval.i = prim_number(&yytext[1]); return(NAMEDPRIM);}
break;
case -1:
break;
default:
fprintf(yyout,"bad switch yylook %d",nstr);
} return(0); }
/* end of yylex */
static int ocbuf = 0;
static int pbbuf[400];
static int input()
{ int c;
if (ocbuf) {c = pbbuf[--ocbuf]; }
else {
c = getc(fp);
if (c == EOF) c = 0;
}
return(c);
}
static unput(c)
char c;
{
if (c) pbbuf[ocbuf++] = c;
}
# include <ctype.h>
static readcomment()
{ char c;
while ((c = input()) && c != '\"')
if (c == '\n') linenum++;
if (!c) yyerror("unterminated comment");
}
char *walloc(s) char *s;
{ char *p, *malloc();
p = malloc((unsigned) (strlen(s) + 1));
if (p == (char *) 0) yyerror("out of variable string space");
strcpy(p, s);
return(p);
}
static int slexsave(type)
int type;
{
yylval.c = walloc(&yytext[1]);
if (yylval.c == 0) yerr("cannot create symbol %s", yytext);
return(type);
}
static int lexsave(type)
int type;
{
yylval.c = walloc(yytext);
if (yylval.c == 0) yerr("cannot create string %s", yytext);
return(type);
}
static int varlex()
{
lexsave(0);
if (yytext[yyleng-1] == ':') return(KEYWORD);
else if (islower(yytext[0])) return(LOWERCASEVAR);
else return(UPPERCASEVAR);
}
static int lexlstr()
{ char *p, *q;
yylval.c = p = walloc(&yytext[1]);
*(p + yyleng -2) = '\0';
return(LITSTR);
}
static int prim_number(name)
char *name;
{ struct prim_names *p;
for (p = prim_table; *(p->p_name); p++) {
if (strcmp(p->p_name, name) == 0)
return(p->p_number);
}
yerr("unknown primitive name %s", name);
return(0);
}
int yyvstop[] ={
0,
36,
0,
1,
0,
2,
0,
32,
36,
0,
3,
36,
0,
15,
36,
0,
36,
0,
36,
0,
24,
36,
0,
25,
36,
0,
23,
36,
0,
28,
36,
0,
17,
18,
20,
0,
36,
0,
33,
36,
0,
36,
0,
35,
36,
0,
20,
0,
20,
0,
26,
36,
0,
27,
36,
0,
34,
36,
0,
20,
0,
20,
0,
20,
0,
20,
0,
31,
36,
0,
30,
32,
36,
0,
29,
31,
36,
0,
22,
0,
14,
0,
19,
0,
20,
0,
20,
0,
20,
0,
21,
0,
4,
0,
5,
0,
38,
0,
38,
0,
20,
0,
20,
0,
20,
0,
20,
0,
20,
0,
20,
0,
20,
0,
18,
0,
18,
20,
0,
16,
20,
0,
38,
0,
20,
0,
20,
0,
10,
20,
0,
20,
0,
20,
0,
20,
0,
20,
0,
18,
0,
16,
0,
20,
0,
38,
0,
20,
0,
20,
0,
7,
20,
0,
20,
0,
20,
0,
11,
20,
0,
16,
0,
16,
20,
0,
38,
0,
6,
20,
0,
12,
20,
0,
20,
0,
20,
0,
9,
20,
0,
16,
0,
38,
0,
20,
0,
20,
0,
38,
0,
20,
0,
20,
0,
38,
0,
20,
0,
20,
0,
38,
0,
20,
0,
13,
20,
0,
37,
38,
0,
20,
0,
8,
20,
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, 1,5,
0,0, 0,0, 0,0, 4,4,
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,6, 1,7,
1,8, 1,9, 4,4, 0,0,
1,10, 1,11, 1,12, 0,0,
1,3, 0,0, 1,13, 1,14,
0,0, 1,15, 0,0, 0,0,
0,0, 0,0, 0,0, 0,0,
0,0, 0,0, 0,0, 1,16,
1,17, 1,18, 0,0, 1,19,
0,0, 0,0, 1,20, 0,0,
1,21, 0,0, 0,0, 65,53,
0,0, 65,53, 0,0, 2,30,
2,7, 2,8, 2,9, 0,0,
0,0, 8,32, 0,0, 2,12,
0,0, 0,0, 0,0, 2,13,
2,14, 8,0, 8,0, 0,0,
1,22, 0,0, 1,23, 1,24,
0,0, 0,0, 1,20, 9,33,
2,16, 2,17, 2,18, 1,25,
2,19, 25,46, 45,58, 9,33,
9,0, 2,21, 21,45, 1,26,
8,0, 26,47, 46,59, 47,60,
1,27, 1,28, 28,51, 8,32,
8,0, 8,0, 10,34, 8,32,
27,48, 1,29, 8,0, 44,57,
8,32, 48,61, 10,34, 10,34,
27,49, 2,22, 49,62, 2,23,
2,24, 9,33, 9,33, 50,63,
27,50, 9,33, 51,64, 52,65,
2,25, 8,32, 9,33, 57,70,
58,71, 59,72, 61,73, 62,74,
2,26, 63,75, 64,76, 70,81,
71,82, 2,27, 2,28, 67,68,
10,35, 10,34, 72,83, 9,33,
10,34, 73,84, 2,31, 74,85,
75,86, 10,34, 78,77, 8,0,
81,88, 84,89, 85,90, 88,91,
89,92, 8,32, 90,93, 91,94,
92,95, 93,96, 94,97, 95,98,
96,99, 97,100, 10,34, 98,101,
101,102, 0,0, 0,0, 0,0,
0,0, 0,0, 0,0, 9,33,
0,0, 0,0, 0,0, 0,0,
15,36, 0,0, 15,15, 15,15,
15,15, 15,15, 15,15, 15,15,
15,15, 15,15, 15,15, 15,15,
15,37, 0,0, 67,77, 0,0,
0,0, 0,0, 10,34, 15,20,
15,20, 15,20, 15,20, 15,20,
15,20, 15,20, 15,20,