home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Resource Library: Graphics
/
graphics-16000.iso
/
msdos
/
raytrace
/
vort
/
vort
/
text3d
/
lex.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-02-11
|
16KB
|
916 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 BUFSIZ
# 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;
#include <math.h>
#include "text3d.h"
#include "gram.h"
extern int linecount;
extern double atof();
# 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:
return(OUTPUT);
break;
case 2:
return(DRAWSTR);
break;
case 3:
return(COLOUR);
break;
case 4:
return(COLOUR);
break;
case 5:
return(TEXTSIZE);
break;
case 6:
return(AMBIENT);
break;
case 7:
return(REFLECTANCE);
break;
case 8:
return(TRANSPARENCY);
break;
case 9:
return(MATERIAL);
break;
case 10:
return(TEXTRADIUS);
break;
case 11:
return(FIXEDWIDTH);
break;
case 12:
return(CENTERTEXT);
break;
case 13:
return(CENTERTEXT);
break;
case 14:
return(TEXTANG);
break;
case 15:
return(FONT);
break;
case 16:
return(DRAWCHAR);
break;
case 17:
return(BOXFIT);
break;
case 18:
return(BOXTEXT);
break;
case 19:
return(MOVE);
break;
case 20:
return(SCALE);
break;
case 21:
return(TRANSLATE);
break;
case 22:
return(ROTATE);
break;
case 23:
return(FIXEDWIDTH);
break;
case 24:
return(CENTERTEXT);
break;
case 25:
return(TRUE);
break;
case 26:
return(FALSE);
break;
case 27:
return(CYL_SPH);
break;
case 28:
return(BOX_CYL);
break;
case 29:
{
yylval.y_int = atoi(yytext);
return(INTEGER);
}
break;
case 30:
{
yylval.y_flt = atof(yytext);
return(FLOAT);
}
break;
case 31:
{
int braces = 1, c;
while ((c = getchar()) != '{')
if (c == '\n')
linecount++;
while (braces) {
c = getchar();
if (c == '\n')
linecount++;
if (c == '\\') {
c = getchar();
putchar(c);
if (c == '\n')
linecount++;
} else {
if (c == '{')
braces++;
if (c == '}')
braces--;
if (c == EOF) {
fprintf(stderr, "Unterminated copy\n");
exit(1);
}
if (braces)
putchar(c);
}
}
while ((c = getchar()) == '\n' || c == ' ' || c == '\t' )
if (c == '\n')
linecount++;
ungetc(c, stdin);
putchar('\n');
}
break;
case 32:
return(PLUS);
break;
case 33:
return(MINUS);
break;
case 34:
return(DIV);
break;
case 35:
return(MULT);
break;
case 36:
return(PCENT);
break;
case 37:
return(POWER);
break;
case 38:
return(COMMA);
break;
case 39:
return(LP);
break;
case 40:
return(RP);
break;
case 41:
return(EQUALS);
break;
case 42:
{
int c1, c2;
c1 = getchar();
if (c1 == '\\')
c1 = getchar();
if (c1 == '\n' || c1 == EOF)
yyerror("syntax error");
while((c2 = getchar()) != '\'')
if (c2 == '\n' || c2 == EOF)
yyerror("syntax error");
yylval.y_int = c1;
return(INTEGER);
}
break;
case 43:
{
char buf[BUFSIZ], *p;
for (p = buf; (*p = getchar()) != '"'; p++) {
if (*p == '\n' || *p == EOF) {
sprintf(buf, "syntax error\n", linecount);
yyerror(buf);
}
if (*p == '\\')
*p = getchar();
}
*p = 0;
yylval.y_str = (char *)malloc(strlen(buf) + 1);
strcpy(yylval.y_str, buf);
return(STRING);
}
break;
case 44:
{
return(LBRACE);
}
break;
case 45:
{
return(RBRACE);
}
break;
case 46:
{
linecount++;
}
break;
case 47:
{
;
}
break;
case 48:
{
int c1, c2;
int comline, incomment = 1;
char buf[BUFSIZ];
comline = linecount;
do {
while ((c1 = getchar()) != '*' && c1 != '/' && c1 != EOF)
if (c1 == '\n')
linecount++;
c2 = getchar();
if (c2 == '\n')
linecount++;
if (c1 == '*' && c2 == '/')
incomment--;
if (c1 == '/' && c2 == '*') {
incomment++;
comline = linecount;
}
} while (incomment && c2 != EOF);
if (c1 == EOF || c2 == EOF) {
fprintf(stderr, "text3d: unterminated comment - started line %d.\n", comline);
exit(1);
}
}
break;
case -1:
break;
default:
fprintf(yyout,"bad switch yylook %d",nstr);
} return(0); }
/* end of yylex */
int yyvstop[] = {
0,
29,
0,
29,
0,
47,
0,
46,
0,
43,
0,
36,
0,
42,
0,
39,
0,
40,
0,
35,
0,
32,
0,
38,
0,
33,
0,
30,
0,
34,
0,
29,
0,
41,
0,
37,
0,
44,
0,
45,
0,
48,
0,
31,
0,
15,
0,
19,
0,
25,
0,
4,
0,
26,
0,
20,
0,
17,
0,
3,
0,
1,
0,
22,
0,
6,
0,
28,
0,
18,
0,
27,
0,
2,
0,
14,
0,
16,
0,
9,
0,
5,
0,
21,
0,
12,
24,
0,
13,
0,
11,
23,
0,
10,
0,
7,
0,
8,
0,
0};
# define YYTYPE int
struct yywork { YYTYPE verify, advance; } yycrank[] = {
0,0, 0,0, 0,0, 0,0,
0,0, 0,0, 0,0, 0,0,
0,0, 0,0, 1,3, 1,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, 0,0, 0,0,
0,0, 1,3, 0,0, 1,5,
0,0, 0,0, 1,6, 0,0,
1,7, 1,8, 1,9, 1,10,
1,11, 1,12, 1,13, 1,14,
1,15, 1,16, 1,16, 1,16,
1,16, 1,16, 1,16, 1,16,
1,16, 1,16, 1,16, 15,31,
0,0, 0,0, 1,17, 14,14,
14,14, 14,14, 14,14, 14,14,
14,14, 14,14, 14,14, 14,14,
14,14, 16,14, 0,0, 16,16,
16,16, 16,16, 16,16, 16,16,
16,16, 16,16, 16,16, 16,16,
16,16, 0,0, 0,0, 0,0,
0,0, 0,0, 0,0, 0,0,
0,0, 0,0, 0,0, 1,18,
0,0, 0,0, 1,19, 1,20,
1,21, 1,22, 27,46, 1,23,
32,49, 37,55, 23,38, 24,41,
21,34, 0,0, 1,24, 19,32,
1,25, 20,33, 23,39, 1,26,
1,27, 1,28, 21,35, 22,37,
23,40, 24,42, 25,43, 26,44,
1,29, 28,47, 1,30, 33,50,
21,36, 34,51, 35,52, 36,54,
38,56, 26,45, 35,53, 39,57,
40,58, 41,59, 28,48, 42,60,
43,61, 44,62, 45,63, 46,64,
47,65, 48,66, 49,68, 50,69,
51,72, 52,73, 53,74, 54,75,
55,76, 56,77, 50,70, 57,78,
58,79, 59,80, 60,81, 61,82,
62,83, 63,84, 64,85, 65,86,
66,87, 48,67, 67,88, 68,89,
50,71, 69,90, 70,91, 71,92,
72,93, 73,95, 75,97, 76,98,
73,96, 77,100, 78,101, 80,102,
82,103, 83,104, 84,105, 85,106,
86,107, 72,94, 87,110, 89,111,
90,112, 91,113, 92,114, 76,99,
93,115, 94,116, 96,117, 97,118,
98,119, 99,120, 101,121, 102,122,
103,123, 86,108, 86,109, 104,124,
105,125, 107,126, 108,127, 109,128,
110,129, 111,131, 112,132, 114,133,
110,130, 115,134, 116,135, 118,136,
119,137, 120,138, 121,139, 122,140,
124,141, 126,142, 127,143, 128,144,
129,145, 130,146, 134,147, 135,148,
137,149, 139,150, 140,151, 141,152,
143,153, 144,154, 145,155, 146,156,
147,157, 148,158, 150,159, 152,160,
153,161, 155,162, 156,163, 157,164,
158,165, 159,166, 160,167, 161,168,
163,169, 167,170, 169,171, 171,172,
0,0};
struct yysvf yysvec[] = {
0, 0, 0,
yycrank+1, 0, yyvstop+1,
yycrank+0, yysvec+1, yyvstop+3,
yycrank+0, 0, yyvstop+5,
yycrank+0, 0, yyvstop+7,
yycrank+0, 0, yyvstop+9,
yycrank+0, 0, yyvstop+11,
yycrank+0, 0, yyvstop+13,
yycrank+0, 0, yyvstop+15,
yycrank+0, 0, yyvstop+17,
yycrank+0, 0, yyvstop+19,
yycrank+0, 0, yyvstop+21,
yycrank+0, 0, yyvstop+23,
yycrank+0, 0, yyvstop+25,
yycrank+15, 0, yyvstop+27,
yycrank+17, 0, yyvstop+29,
yycrank+27, 0, yyvstop+31,
yycrank+0, 0, yyvstop+33,
yycrank+0, 0, yyvstop+35,
yycrank+2, 0, 0,
yycrank+2, 0, 0,
yycrank+7, 0, 0,
yycrank+5, 0, 0,
yycrank+9, 0, 0,
yycrank+10, 0, 0,
yycrank+5, 0, 0,
yycrank+22, 0, 0,
yycrank+3, 0, 0,
yycrank+24, 0, 0,
yycrank+0, 0, yyvstop+37,
yycrank+0, 0, yyvstop+39,
yycrank+0, 0, yyvstop+41,
yycrank+6, 0, 0,
yycrank+7, 0, 0,
yycrank+19, 0, 0,
yycrank+22, 0, 0,
yycrank+23, 0, 0,
yycrank+8, 0, 0,
yycrank+24, 0, 0,
yycrank+15, 0, 0,
yycrank+26, 0, 0,
yycrank+21, 0, 0,
yycrank+21, 0, 0,
yycrank+24, 0, 0,
yycrank+39, 0, 0,
yycrank+26, 0, 0,
yycrank+46, 0, 0,
yycrank+24, 0, 0,
yycrank+48, 0, 0,
yycrank+41, 0, 0,
yycrank+52, 0, 0,
yycrank+32, 0, 0,
yycrank+38, 0, 0,
yycrank+29, 0, 0,
yycrank+56, 0, 0,
yycrank+33, 0, 0,
yycrank+38, 0, 0,
yycrank+54, 0, 0,
yycrank+40, 0, 0,
yycrank+56, 0, 0,
yycrank+57, 0, 0,
yycrank+47, 0, 0,
yycrank+52, 0, 0,
yycrank+64, 0, 0,
yycrank+54, 0, 0,
yycrank+47, 0, 0,
yycrank+54, 0, 0,
yycrank+65, 0, 0,
yycrank+66, 0, 0,
yycrank+70, 0, 0,
yycrank+65, 0, 0,
yycrank+70, 0, 0,
yycrank+71, 0, 0,
yycrank+59, 0, 0,
yycrank+0, 0, yyvstop+43,
yycrank+59, 0, 0,
yycrank+76, 0, 0,
yycrank+76, 0, 0,
yycrank+78, 0, 0,
yycrank+0, 0, yyvstop+45,
yycrank+65, 0, 0,
yycrank+0, 0, yyvstop+47,
yycrank+63, 0, 0,
yycrank+80, 0, 0,
yycrank+66, 0, 0,
yycrank+82, 0, 0,
yycrank+87, 0, 0,
yycrank+71, 0, 0,
yycrank+0, 0, yyvstop+49,
yycrank+77, 0, 0,
yycrank+67, 0, 0,
yycrank+73, 0, 0,
yycrank+70, 0, 0,
yycrank+78, 0, 0,
yycrank+92, 0, 0,
yycrank+0, 0, yyvstop+51,
yycrank+80, 0, 0,
yycrank+83, 0, 0,
yycrank+92, 0, 0,
yycrank+81, 0, 0,
yycrank+0, 0, yyvstop+53,
yycrank+79, 0, 0,
yycrank+94, 0, 0,
yycrank+84, 0, 0,
yycrank+104, 0, 0,
yycrank+103, 0, 0,
yycrank+0, 0, yyvstop+55,
yycrank+95, 0, 0,
yycrank+109, 0, 0,
yycrank+102, 0, 0,
yycrank+100, 0, 0,
yycrank+93, 0, 0,
yycrank+102, 0, 0,
yycrank+0, 0, yyvstop+57,
yycrank+95, 0, 0,
yycrank+97, 0, 0,
yycrank+98, 0, 0,
yycrank+0, 0, yyvstop+59,
yycrank+111, 0, 0,
yycrank+119, 0, 0,
yycrank+103, 0, 0,
yycrank+113, 0, 0,
yycrank+122, 0, 0,
yycrank+0, 0, yyvstop+61,
yycrank+104, 0, 0,
yycrank+0, 0, yyvstop+63,
yycrank+118, 0, 0,
yycrank+122, 0, 0,
yycrank+101, 0, 0,
yycrank+127, 0, 0,
yycrank+128, 0, 0,
yycrank+0, 0, yyvstop+65,
yycrank+0, 0, yyvstop+67,
yycrank+0, 0, yyvstop+69,
yycrank+125, 0, 0,
yycrank+126, 0, 0,
yycrank+0, 0, yyvstop+71,
yycrank+114, 0, 0,
yycrank+0, 0, yyvstop+73,
yycrank+129, 0, 0,
yycrank+122, 0, 0,
yycrank+134, 0, 0,
yycrank+0, 0, yyvstop+75,
yycrank+127, 0, 0,
yycrank+132, 0, 0,
yycrank+118, 0, 0,
yycrank+121, 0, 0,
yycrank+116, 0, 0,
yycrank+117, 0, 0,
yycrank+0, 0, yyvstop+77,
yycrank+122, 0, 0,
yycrank+0, 0, yyvstop+79,
yycrank+129, 0, 0,
yycrank+123, 0, 0,
yycrank+0, 0, yyvstop+81,
yycrank+140, 0, 0,
yycrank+141, 0, 0,
yycrank+127, 0, 0,
yycrank+128, 0, 0,
yycrank+141, 0, 0,
yycrank+147, 0, 0,
yycrank+132, 0, 0,
yycrank+0, 0, yyvstop+83,
yycrank+138, 0, 0,
yycrank+0, 0, yyvstop+85,
yycrank+0, 0, yyvstop+88,
yycrank+0, 0, yyvstop+90,
yycrank+148, 0, 0,
yycrank+0, 0, yyvstop+93,
yycrank+151, 0, 0,
yycrank+0, 0, yyvstop+95,
yycrank+130, 0, 0,
yycrank+0, 0, yyvstop+97,
0, 0, 0};
struct yywork *yytop = yycrank+251;
struct yysvf *yybgin = yysvec+1;
char yymatch[] = {
00 ,01 ,01 ,01 ,01 ,01 ,01 ,01 ,
01 ,011 ,01 ,01 ,01 ,01 ,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 ,01 ,01 ,
'0' ,'0' ,'0' ,'0' ,'0' ,'0' ,'0' ,'0' ,
'0' ,'0' ,01 ,01 ,01 ,01 ,01 ,01 ,
01 ,01 ,01 ,01 ,01 ,01 ,01 ,01 ,
01 ,01 ,01 ,01 ,01 ,01 ,01 ,01 ,
01 ,01 ,01 ,01 ,01 ,01 ,01 ,01 ,
01 ,01 ,01 ,01 ,01 ,01 ,01 ,01 ,
01 ,01 ,01 ,01 ,01 ,01 ,01 ,01 ,
01 ,01 ,01 ,01 ,01 ,01 ,01 ,01 ,
01 ,01 ,01 ,01 ,01 ,01 ,01 ,01 ,
01 ,01 ,01 ,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,0,0,0,0,0,0,0,
0};
#ifndef lint
static char ncform_sccsid[] = "@(#)ncform 1.6 88/02/08 SMI"; /* from S5R2 1.2 */
#endif
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);
}