Exemplo n.º 1
0
/* put out other arrays, copy the parsers */
static void
others()
{
	extern int gen_lines;
	int c, i, j;
	int tmpline;

	finput = fopen(parser, "r");
	if (finput == NULL)
/*
 * TRANSLATION_NOTE  -- This is a message from yacc.
 *	This message is passed to error() function.
 *	This error message is issued when yacc can not find
 *	the parser to be copied.
 */
		error(gettext(
		"cannot find parser %s"),
		    parser);

	warray(L"yyr1", levprd, nprod);

	aryfil(temp1, nprod, 0);
					/* had_act[i] is either 1 or 0 */
	PLOOP(1, i)
		temp1[i] = ((prdptr[i+1] - prdptr[i]-2) << 1) | had_act[i];
	warray(L"yyr2", temp1, nprod);

	aryfil(temp1, nstate, -10000000);
	TLOOP(i)
		for (j = tstates[i]; j != 0; j = mstates[j])
			temp1[j] = tokset[i].value;
	NTLOOP(i)
		for (j = ntstates[i]; j != 0; j = mstates[j])
			temp1[j] = -i;
	warray(L"yychk", temp1, nstate);

	warray(L"yydef", defact, nstate);

	if ((fdebug = fopen(DEBUGNAME, "r")) == NULL)
		error("cannot open yacc.debug");
	while ((c = getwc(fdebug)) != EOF)
		(void) putwc(c, ftable);
	(void) fclose(fdebug);
	ZAPFILE(DEBUGNAME);

	if (gen_lines)
		(void) fprintf(ftable, "# line\t1 \"%s\"\n", parser);
	tmpline = 1;
	/* copy parser text */
	while ((c = getwc(finput)) != EOF) {
		if (c == '\n')
			tmpline++;
		if (c == L'$') {
			if ((c = getwc(finput)) != L'A')
				(void) putwc(L'$', ftable);
			else { /* copy actions */
				tmpline++;
				faction = fopen(ACTNAME, "r");
				if (faction == NULL)
/*
 * TRANSLATION_NOTE  -- This is a message from yacc.
 *	This message is passed to error() function.
 *	This error is issued when yacc can not open a
 *	temporary file to be used. You do not need to
 *	use the word 'tempfile'. You can translate it to
 *	mean 'temporary file'.
 */
					error(gettext(
					"cannot open action tempfile"));
				while ((c = getwc(faction)) != EOF)
					(void) putwc(c, ftable);
				(void) fclose(faction);
				if (gen_lines)
					(void) fprintf(ftable,
					    "\n# line\t%d \"%s\"",
					    tmpline,
					    parser);
				ZAPFILE(ACTNAME);
				c = getwc(finput);
			}
		}
		(void) putwc(c, ftable);
	}
	(void) fclose(ftable);
}
Exemplo n.º 2
0
Arquivo: y1.c Projeto: pkgw/iraf
/* put out other arrays, copy the parsers */
static void
others ()
{
    extern int gen_lines;
    int c, i, j;
    int tmpline;

    finput = fopen (parser, "r");
    if (finput == NULL)
/*
 * TRANSLATION_NOTE  -- This is a message from yacc.
 *	This message is passed to error() function.
 *	This error message is issued when yacc can not find
 *	the parser to be copied.
 */
	error ("cannot find parser %s", parser);

    warray ("yyr1", levprd, nprod);

    aryfil (temp1, nprod, 0);
    /* had_act[i] is either 1 or 0 */
/* original
	PLOOP(1, i)
		temp1[i] = ((prdptr[i+1] - prdptr[i]-2) << 1) | had_act[i];
*/
    PLOOP (1, i) temp1[i] = prdptr[i + 1] - prdptr[i] - 2;

    warray ("yyr2", temp1, nprod);

    aryfil (temp1, nstate, -1000);
    TLOOP (i) for (j = tstates[i]; j != 0; j = mstates[j])
	temp1[j] = tokset[i].value;
    NTLOOP (i) for (j = ntstates[i]; j != 0; j = mstates[j])
	temp1[j] = -i;
    warray ("yychk", temp1, nstate);
    warray ("yydef", defact, nstate);

    fclose (ftable);
    fclose (fudecl);

    if ((fdebug = fopen (DEBUGNAME, "r")) == NULL)
	error ("cannot open yacc.debug");
    while ((c = getc (fdebug)) != EOF)
	(void) putc (c, fsppout);
    (void) fclose (fdebug);
    ZAPFILE (DEBUGNAME);

    if (gen_lines)
	(void) fprintf (fsppout, "# line\t1 \"%s\"\n", parser);
    tmpline = 1;
    /* copy parser text */
    while ((c = getc (finput)) != EOF) {
	if (c == '\n')
	    tmpline++;
	if (c == '$') {
	    if ((c = getc (finput)) == 'A') {
		/* Replace $A macro by the user declarations.
		 */
		fudecl = fopen (UDFILE, "r");
		if (fudecl == NULL)
		    error ("cannot reopen user declarations tempfile");
		while ((c = getc (fudecl)) != EOF)
		    putc (c, fsppout);
		fclose (fudecl);
		ZAPFILE (UDFILE);
		/* Skip remainder of line following macro.
		 */
		while ((c = getc (finput)) != '\n' && c != EOF);

	    } else if (c == 'B') {
		/* Replace $B macro by the parser tables.
		 */
		ftable = fopen (TABFILE, "r");
		if (ftable == NULL)
		    error ("cannot reopen parser tables tempfile");
		while ((c = getc (ftable)) != EOF)
		    putc (c, fsppout);
		fclose (ftable);
		ZAPFILE (TABFILE);
		/* Skip remainder of line following macro.
		 */
		while ((c = getc (finput)) != '\n' && c != EOF);

	    } else if (c == 'C') {
		/* Replace $C macro by user-supplied actions.
		 */
		faction = fopen (ACTNAME, "r");
		if (faction == NULL)
		    error ("cannot reopen action tempfile");
		while ((c = getc (faction)) != EOF)
		    putc (c, fsppout);
		fclose (faction);
		ZAPFILE (ACTNAME);
		/* Skip remainder of line following macro.
		 */
		while ((c = getc (finput)) != '\n' && c != EOF);

	    } else {
		putc ('$', fsppout);
		putc (c, fsppout);
	    }

	} else
	    putc (c, fsppout);
    }

    fclose (fsppout);
}