plan9port

fork of plan9port with libvec, libstr and libsdb
Log | Files | Refs | README | LICENSE

header.c (3425B)


      1 # include "ldefs.h"
      2 
      3 extern int nine;
      4 
      5 void
      6 phead1(void)
      7 {
      8 	Bprint(&fout,"typedef unsigned char Uchar;\n");
      9 	if (nine) {
     10 		Bprint(&fout,"# include <u.h>\n");
     11 		Bprint(&fout,"# include <libc.h>\n");
     12 	}
     13 	Bprint(&fout,"# include <stdio.h>\n");
     14 	Bprint(&fout, "# define U(x) x\n");
     15 	Bprint(&fout, "# define NLSTATE yyprevious=YYNEWLINE\n");
     16 	Bprint(&fout,"# define BEGIN yybgin = yysvec + 1 +\n");
     17 	Bprint(&fout,"# define INITIAL 0\n");
     18 	Bprint(&fout,"# define YYLERR yysvec\n");
     19 	Bprint(&fout,"# define YYSTATE (yyestate-yysvec-1)\n");
     20 	Bprint(&fout,"# define YYOPTIM 1\n");
     21 # ifdef DEBUG
     22 	Bprint(&fout,"# define LEXDEBUG 1\n");
     23 # endif
     24 	Bprint(&fout,"# define YYLMAX 200\n");
     25 	Bprint(&fout,
     26 "# define unput(c) {yytchar= (c);if(yytchar=='\\n')yylineno--;*yysptr++=yytchar;}\n");
     27 	Bprint(&fout,"# define yymore() (yymorfg=1)\n");
     28 	Bprint(&fout,"# define ECHO fprintf(yyout, \"%%s\",yytext)\n");
     29 	Bprint(&fout,"# define REJECT { nstr = yyreject(); goto yyfussy;}\n");
     30 	Bprint(&fout,"int yyleng; extern char yytext[];\n");
     31 	Bprint(&fout,"int yymorfg;\n");
     32 	Bprint(&fout,"extern Uchar *yysptr, yysbuf[];\n");
     33 	Bprint(&fout,"int yytchar;\n");
     34 /*	Bprint(&fout,"FILE *yyin = stdin, *yyout = stdout;\n"); */
     35 	Bprint(&fout,"FILE *yyin, *yyout;\n");
     36 	Bprint(&fout,"extern int yylineno;\n");
     37 	Bprint(&fout,"struct yysvf { \n");
     38 	Bprint(&fout,"\tstruct yywork *yystoff;\n");
     39 	Bprint(&fout,"\tstruct yysvf *yyother;\n");
     40 	Bprint(&fout,"\tint *yystops;};\n");
     41 	Bprint(&fout,"struct yysvf *yyestate;\n");
     42 	Bprint(&fout,"extern struct yysvf yysvec[], *yybgin;\n");
     43 	Bprint(&fout,"int yylook(void), yywrap(void), yyback(int *, int);\n");
     44 	if(nine) {
     45 		Bprint(&fout,
     46 				"int infd, outfd;\n"
     47 				"\n"
     48 				"void\n"
     49 				"output(char c)\n"
     50 				"{\n"
     51 				"	int rv;\n"
     52 				"	if ((rv = write(outfd, &c, 1)) < 0)\n"
     53 				"		sysfatal(\"output: %%r\");\n"
     54 				"	if (rv == 0)\n"
     55 				"		sysfatal(\"output: EOF?\");\n"
     56 				"}\n"
     57 				"\n"
     58 				"int\n"
     59 				"input(void)\n"
     60 				"{\n"
     61 				"	if(yysptr > yysbuf)\n"
     62 				"		yytchar = U(*--yysptr);\n"
     63 				"	else {\n"
     64 				"		int rv;\n"
     65 				"		if ((rv = read(infd, &yytchar, 1)) < 0)\n"
     66 				"			sysfatal(\"input: %%r\");\n"
     67 				"		if (rv == 0)\n"
     68 				"			return 0;\n"
     69 				"	}\n"
     70 				"	if (yytchar == '\\n')\n"
     71 				"		yylineno++;\n"
     72 				"	return yytchar;\n"
     73 				"}\n");
     74 	}
     75 	else {
     76 		Bprint(&fout,"# define output(c) putc(c,yyout)\n");
     77 		Bprint(&fout, "%s%d%s\n",
     78  		 "# define input() (((yytchar=yysptr>yysbuf?U(*--yysptr):getc(yyin))==",
     79 		'\n',
     80  		"?(yylineno++,yytchar):yytchar)==EOF?0:yytchar)");
     81 	}
     82 }
     83 
     84 void
     85 phead2(void)
     86 {
     87 	Bprint(&fout,"while((nstr = yylook()) >= 0){\n");
     88 	Bprint(&fout,"goto yyfussy; yyfussy: switch(nstr){\n");
     89 	Bprint(&fout,"case 0:\n");
     90 	Bprint(&fout,"if(yywrap()) return(0); break;\n");
     91 }
     92 
     93 void
     94 ptail(void)
     95 {
     96 	if(!pflag){
     97 		Bprint(&fout,"case -1:\nbreak;\n");		/* for reject */
     98 		Bprint(&fout,"default:\n");
     99 		Bprint(&fout,"fprintf(yyout,\"bad switch yylook %%d\",nstr);\n");
    100 		Bprint(&fout,"}} return(0); }\n");
    101 		Bprint(&fout,"/* end of yylex */\n");
    102 	}
    103 	pflag = 1;
    104 }
    105 
    106 void
    107 statistics(void)
    108 {
    109 	fprint(errorf,"%d/%d nodes(%%e), %d/%d positions(%%p), %d/%d (%%n), %ld transitions\n",
    110 		tptr, treesize, (int)(nxtpos-positions), maxpos, stnum+1, nstates, rcount);
    111 	fprint(errorf, ", %d/%d packed char classes(%%k)", (int)(pcptr-pchar), pchlen);
    112 	fprint(errorf,", %d/%d packed transitions(%%a)",nptr, ntrans);
    113 	fprint(errorf, ", %d/%d output slots(%%o)", yytop, outsize);
    114 	fprint(errorf,"\n");
    115 }