Пример #1
0
void output_defines()
{
    register int c, i;
    register char *s;
    FILE *dc_file;

    if(dflag) {
      fprintf(defines_file, "#ifndef _yacc_defines_h_\n");
      fprintf(defines_file, "#define _yacc_defines_h_\n\n");
    }

    /* VM: Print to either code file or defines file but not to both */
    dc_file = dflag ? defines_file : code_file;

    for (i = 2; i < ntokens; ++i)
    {
	s = symbol_name[i];
	if (is_C_identifier(s))
	{
	    fprintf(dc_file, "#define ");
	    c = *s;
	    if (c == '"')
	    {
		while ((c = *++s) != '"')
		{
		    putc(c, dc_file);
		}
	    }
	    else
	    {
		do
		{
		    putc(c, dc_file);
		}
		while ((c = *++s));
	    }
	    ++outline;
	    fprintf(dc_file, " %d\n", symbol_value[i]);
	}
    }

    ++outline;
    fprintf(dc_file, "#define YYERRCODE %d\n", symbol_value[1]);

    if (dflag && unionized)
    {
	fclose(union_file);
	union_file = fopen(union_file_name, "r");
	if (union_file == NULL) open_error(union_file_name);
	while ((c = getc(union_file)) != EOF) {
	  putc(c, defines_file);
	}
	fprintf(defines_file, "extern YYSTYPE yylval;\n");
    }

    if(dflag) {
      fprintf(defines_file, "\n#endif\n");
    }
}
Пример #2
0
static void
output_defines(FILE * fp)
{
    int c, i;
    char *s;

    for (i = 2; i < ntokens; ++i)
    {
	s = symbol_name[i];
	if (is_C_identifier(s) && (!sflag || *s != '"'))
	{
	    fprintf(fp, "#define ");
	    c = *s;
	    if (c == '"')
	    {
		while ((c = *++s) != '"')
		{
		    putc(c, fp);
		}
	    }
	    else
	    {
		do
		{
		    putc(c, fp);
		}
		while ((c = *++s) != 0);
	    }
	    if (fp == code_file)
		++outline;
	    fprintf(fp, " %d\n", symbol_value[i]);
	}
    }

    if (fp == code_file)
	++outline;
    if (fp != defines_file || iflag)
	fprintf(fp, "#define YYERRCODE %d\n", symbol_value[1]);

    if (fp == defines_file || (iflag && !dflag))
    {
	if (unionized)
	{
	    if (union_file != 0)
	    {
		rewind(union_file);
		while ((c = getc(union_file)) != EOF)
		    putc(c, fp);
	    }
	    fprintf(fp, "extern YYSTYPE %slval;\n", symbol_prefix);
	}
    }
}
Пример #3
0
void output_defines()
{
    register int c, i;
    register char *s;
    FILE *dc_file;

    if(dflag) {
	char *p, *tmp = strdup(defines_file_name);
	for (p = tmp; *p; p++)
	    if (!isalnum(*p))
		*p = '_';
	fprintf(defines_file, "#ifndef _%s_\n", tmp);
	fprintf(defines_file, "#define _%s_\n\n", tmp);
	free(tmp);
    }

    /* VM: Print to either code file or defines file but not to both */
    dc_file = dflag ? defines_file : code_file;

    for (i = 2; i < ntokens; ++i)
    {
	s = symbol_name[i];
	if (is_C_identifier(s))
	{
	    fprintf(dc_file, "#define ");
	    c = *s;
	    if (c == '"')
	    {
		while ((c = *++s) != '"')
		{
		    putc(c, dc_file);
		}
	    }
	    else
	    {
		do
		{
		    putc(c, dc_file);
		}
		while ((c = *++s));
	    }
	    if (!dflag) ++outline;
	    fprintf(dc_file, " %d\n", symbol_value[i]);
	}
    }

    ++outline;
    fprintf(dc_file, "#define YYERRCODE %d\n", symbol_value[1]);

    if (dflag && (unionized || location_defined))
    {
	fclose(union_file);
	union_file = fopen(union_file_name, "r");
	if (union_file == NULL) open_error(union_file_name);
	while ((c = getc(union_file)) != EOF) {
	  putc(c, defines_file);
	}
	if (unionized)
	    fprintf(defines_file, "extern YYSTYPE yylval;\n");
    }

    if(dflag) {
	fprintf(defines_file, "#if defined(YYPOSN)\n"
			      "extern YYPOSN yyposn;\n"
			      "#endif\n");
	fprintf(defines_file, "\n#endif\n");
    }
}