Ejemplo n.º 1
0
static void
output_stype(FILE * fp)
{
    if (!unionized && ntags == 0)
    {
	putc_code(fp, '\n');
	putl_code(fp, "#ifndef YYSTYPE\n");
	putl_code(fp, "typedef int YYSTYPE;\n");
	putl_code(fp, "#endif\n");
    }
}
Ejemplo n.º 2
0
static void
output_prefix(FILE * fp)
{
    if (symbol_prefix == NULL)
    {
	symbol_prefix = "yy";
    }
    else
    {
	define_prefixed(fp, "yyparse");
	define_prefixed(fp, "yylex");
	define_prefixed(fp, "yyerror");
	define_prefixed(fp, "yychar");
	define_prefixed(fp, "yyval");
	define_prefixed(fp, "yylval");
	define_prefixed(fp, "yydebug");
	define_prefixed(fp, "yynerrs");
	define_prefixed(fp, "yyerrflag");
	define_prefixed(fp, "yylhs");
	define_prefixed(fp, "yylen");
	define_prefixed(fp, "yydefred");
#if defined(YYBTYACC)
	define_prefixed(fp, "yystos");
#endif
	define_prefixed(fp, "yydgoto");
	define_prefixed(fp, "yysindex");
	define_prefixed(fp, "yyrindex");
	define_prefixed(fp, "yygindex");
	define_prefixed(fp, "yytable");
	define_prefixed(fp, "yycheck");
	define_prefixed(fp, "yyname");
	define_prefixed(fp, "yyrule");
#if defined(YYBTYACC)
	if (locations)
	{
	    define_prefixed(fp, "yyloc");
	    define_prefixed(fp, "yylloc");
	}
	putc_code(fp, '\n');
	putl_code(fp, "#if YYBTYACC\n");

	define_prefixed(fp, "yycindex");
	define_prefixed(fp, "yyctable");

	putc_code(fp, '\n');
	putl_code(fp, "#endif /* YYBTYACC */\n");
	putc_code(fp, '\n');
#endif
    }
    if (CountLine(fp))
	++outline;
    fprintf(fp, "#define YYPREFIX \"%s\"\n", symbol_prefix);
}
Ejemplo n.º 3
0
Archivo: output.c Proyecto: 0mp/freebsd
static void
output_stype(FILE * fp)
{
    if (!unionized && ntags == 0)
    {
	putc_code(fp, '\n');
	putl_code(fp, "#if "
		  "! defined(YYSTYPE) && "
		  "! defined(YYSTYPE_IS_DECLARED)\n");
	putl_code(fp, "/* Default: YYSTYPE is the semantic value type. */\n");
	putl_code(fp, "typedef int YYSTYPE;\n");
	putl_code(fp, "# define YYSTYPE_IS_DECLARED 1\n");
	putl_code(fp, "#endif\n");
    }
}
Ejemplo n.º 4
0
Archivo: output.c Proyecto: 0mp/freebsd
static void
output_accessing_symbols(void)
{
    int i, j;
    int *translate;

    if (nstates != 0)
    {
	translate = TMALLOC(int, nstates);
	NO_SPACE(translate);

	for (i = 0; i < nstates; ++i)
	{
	    int gsymb = accessing_symbol[i];

	    translate[i] = symbol_pval[gsymb];
	}

	putl_code(output_file,
		  "#if defined(YYDESTRUCT_CALL) || defined(YYSTYPE_TOSTRING)\n");
	/* yystos[] may be unused, depending on compile-time defines */
	start_int_table("stos", translate[0]);

	j = 10;
	for (i = 1; i < nstates; ++i)
	{
	    if (j < 10)
		++j;
	    else
	    {
		output_newline();
		j = 1;
	    }

	    output_int(translate[i]);
	}

	end_table();
	FREE(translate);
	putl_code(output_file,
		  "#endif /* YYDESTRUCT_CALL || YYSTYPE_TOSTRING */\n");
    }
Ejemplo n.º 5
0
static void
output_yyerror_call(const char *msg)
{
    FILE *fp = code_file;

    puts_code(fp, "    yyerror(");
    if (parse_param)
    {
	param *p;
	for (p = parse_param; p; p = p->next)
	    fprintf(fp, "%s, ", p->name);
    }
    puts_code(fp, "\"");
    puts_code(fp, msg);
    putl_code(fp, "\");\n");
}
Ejemplo n.º 6
0
static void
output_debug(void)
{
    int i, j, k, max;
    const char **symnam;
    const char *s;

    ++outline;
    fprintf(code_file, "#define YYFINAL %d\n", final_state);

    putl_code(code_file, "#ifndef YYDEBUG\n");
    ++outline;
    fprintf(code_file, "#define YYDEBUG %d\n", tflag);
    putl_code(code_file, "#endif\n");

    if (rflag)
    {
	fprintf(output_file, "#ifndef YYDEBUG\n");
	fprintf(output_file, "#define YYDEBUG %d\n", tflag);
	fprintf(output_file, "#endif\n");
    }

    max = 0;
    for (i = 2; i < ntokens; ++i)
	if (symbol_value[i] > max)
	    max = symbol_value[i];

    ++outline;
    fprintf(code_file, "#define YYMAXTOKEN %d\n", max);

    symnam = TMALLOC(const char *, max + 1);
    NO_SPACE(symnam);

    /* Note that it is  not necessary to initialize the element         */
    /* symnam[max].                                                     */
    for (i = 0; i < max; ++i)
	symnam[i] = 0;
    for (i = ntokens - 1; i >= 2; --i)
	symnam[symbol_value[i]] = symbol_name[i];
    symnam[0] = "end-of-file";

    output_line("#if YYDEBUG");

    start_str_table("name");
    j = 80;
    for (i = 0; i <= max; ++i)
    {
	if ((s = symnam[i]) != 0)
	{
	    if (s[0] == '"')
	    {
		k = 7;
		while (*++s != '"')
		{
		    ++k;
		    if (*s == '\\')
		    {
			k += 2;
			if (*++s == '\\')
			    ++k;
		    }
		}
		j += k;
		if (j > 80)
		{
		    output_newline();
		    j = k;
		}
		fprintf(output_file, "\"\\\"");
		s = symnam[i];
		while (*++s != '"')
		{
		    if (*s == '\\')
		    {
			fprintf(output_file, "\\\\");
			if (*++s == '\\')
			    fprintf(output_file, "\\\\");
			else
			    putc(*s, output_file);
		    }
		    else
			putc(*s, output_file);
		}
		fprintf(output_file, "\\\"\",");
	    }
	    else if (s[0] == '\'')
	    {
		if (s[1] == '"')
		{
		    j += 7;
		    if (j > 80)
		    {
			output_newline();
			j = 7;
		    }
		    fprintf(output_file, "\"'\\\"'\",");
		}
		else
		{
		    k = 5;
		    while (*++s != '\'')
		    {
			++k;
			if (*s == '\\')
			{
			    k += 2;
			    if (*++s == '\\')
				++k;
			}
		    }
		    j += k;
		    if (j > 80)
		    {
			output_newline();
			j = k;
		    }
		    fprintf(output_file, "\"'");
		    s = symnam[i];
		    while (*++s != '\'')
		    {
			if (*s == '\\')
			{
			    fprintf(output_file, "\\\\");
			    if (*++s == '\\')
				fprintf(output_file, "\\\\");
			    else
				putc(*s, output_file);
			}
			else
			    putc(*s, output_file);
		    }
		    fprintf(output_file, "'\",");
		}
	    }
	    else
	    {
		k = (int)strlen(s) + 3;
		j += k;
		if (j > 80)
		{
		    output_newline();
		    j = k;
		}
		putc('"', output_file);
		do
		{
		    putc(*s, output_file);
		}
		while (*++s);
		fprintf(output_file, "\",");
	    }
	}
	else
	{
	    j += 2;
	    if (j > 80)
	    {
		output_newline();
		j = 2;
	    }
	    fprintf(output_file, "0,");
	}
    }
    end_table();
    FREE(symnam);

    start_str_table("rule");
    for (i = 2; i < nrules; ++i)
    {
	fprintf(output_file, "\"%s :", symbol_name[rlhs[i]]);
	for (j = rrhs[i]; ritem[j] > 0; ++j)
	{
	    s = symbol_name[ritem[j]];
	    if (s[0] == '"')
	    {
		fprintf(output_file, " \\\"");
		while (*++s != '"')
		{
		    if (*s == '\\')
		    {
			if (s[1] == '\\')
			    fprintf(output_file, "\\\\\\\\");
			else
			    fprintf(output_file, "\\\\%c", s[1]);
			++s;
		    }
		    else
			putc(*s, output_file);
		}
		fprintf(output_file, "\\\"");
	    }
	    else if (s[0] == '\'')
	    {
		if (s[1] == '"')
		    fprintf(output_file, " '\\\"'");
		else if (s[1] == '\\')
		{
		    if (s[2] == '\\')
			fprintf(output_file, " '\\\\\\\\");
		    else
			fprintf(output_file, " '\\\\%c", s[2]);
		    s += 2;
		    while (*++s != '\'')
			putc(*s, output_file);
		    putc('\'', output_file);
		}
		else
		    fprintf(output_file, " '%c'", s[1]);
	    }
	    else
		fprintf(output_file, " %s", s);
	}
	fprintf(output_file, "\",");
	output_newline();
    }

    end_table();
    output_line("#endif");
}
Ejemplo n.º 7
0
static void
output_error_decl(FILE * fp)
{
    putl_code(fp, "\n");
    putl_code(fp, "/* Parameters sent to yyerror. */\n");
    if (parse_param)
    {
	param *p;

	putl_code(fp, "#ifndef YYERROR_DECL\n");
	fprintf(fp, "#define YYERROR_DECL() yyerror(");
	for (p = parse_param; p; p = p->next)
	    fprintf(fp, "%s %s%s, ", p->type, p->name, p->type2);
	putl_code(fp, "const char *s)\n");
	putl_code(fp, "#endif\n");

	putl_code(fp, "#ifndef YYERROR_CALL\n");
	puts_code(fp, "#define YYERROR_CALL(msg) yyerror(");

	for (p = parse_param; p; p = p->next)
	    fprintf(fp, "%s, ", p->name);

	putl_code(fp, "msg)\n");
	putl_code(fp, "#endif\n");
    }
    else
    {
	putl_code(fp, "#ifndef YYERROR_DECL\n");
	putl_code(fp, "#define YYERROR_DECL() yyerror(const char *s)\n");
	putl_code(fp, "#endif\n");
	putl_code(fp, "#ifndef YYERROR_CALL\n");
	putl_code(fp, "#define YYERROR_CALL(msg) yyerror(msg)\n");
	putl_code(fp, "#endif\n");
    }
}
Ejemplo n.º 8
0
static void
output_lex_decl(FILE * fp)
{
    putl_code(fp, "\n");
    putl_code(fp, "/* Parameters sent to lex. */\n");
    putl_code(fp, "#ifdef YYLEX_PARAM\n");
    if (pure_parser)
    {
	putl_code(fp, "# ifdef YYLEX_PARAM_TYPE\n");
	putl_code(fp, "#  define YYLEX_DECL() yylex(YYSTYPE *yylval,"
		  " YYLEX_PARAM_TYPE YYLEX_PARAM)\n");
	putl_code(fp, "# else\n");
	putl_code(fp, "#  define YYLEX_DECL() yylex(YYSTYPE *yylval,"
		  " void * YYLEX_PARAM)\n");
	putl_code(fp, "# endif\n");
	putl_code(fp, "# define YYLEX yylex(&yylval, YYLEX_PARAM)\n");
    }
    else
    {
	putl_code(fp, "# define YYLEX_DECL() yylex(void *YYLEX_PARAM)\n");
	putl_code(fp, "# define YYLEX yylex(YYLEX_PARAM)\n");
    }
    putl_code(fp, "#else\n");
    if (pure_parser && lex_param)
    {
	param *p;
	puts_code(fp, "# define YYLEX_DECL() yylex(YYSTYPE *yylval, ");
	for (p = lex_param; p; p = p->next)
	    fprintf(fp, "%s %s%s%s", p->type, p->name, p->type2,
		    p->next ? ", " : "");
	putl_code(fp, ")\n");

	puts_code(fp, "# define YYLEX yylex(&yylval, ");
	for (p = lex_param; p; p = p->next)
	    fprintf(fp, "%s%s", p->name, p->next ? ", " : "");
	putl_code(fp, ")\n");
    }
    else if (pure_parser)
    {
	putl_code(fp, "# define YYLEX_DECL() yylex(YYSTYPE *yylval)\n");
	putl_code(fp, "# define YYLEX yylex(&yylval)\n");
    }
    else if (lex_param)
    {
	param *p;
	puts_code(fp, "# define YYLEX_DECL() yylex(");
	for (p = lex_param; p; p = p->next)
	    fprintf(fp, "%s %s%s%s", p->type, p->name, p->type2,
		    p->next ? ", " : "");
	putl_code(fp, ")\n");

	puts_code(fp, "# define YYLEX yylex(");
	for (p = lex_param; p; p = p->next)
	    fprintf(fp, "%s%s", p->name, p->next ? ", " : "");
	putl_code(fp, ")\n");
    }
    else
    {
	putl_code(fp, "# define YYLEX_DECL() yylex(void)\n");
	putl_code(fp, "# define YYLEX yylex()\n");
    }
    putl_code(fp, "#endif\n");
}
Ejemplo n.º 9
0
static void
output_parse_decl(FILE * fp)
{
    putl_code(fp, "\n");
    putl_code(fp, "/* compatibility with bison */\n");
    putl_code(fp, "#ifdef YYPARSE_PARAM\n");
    putl_code(fp, "/* compatibility with FreeBSD */\n");
    putl_code(fp, "# ifdef YYPARSE_PARAM_TYPE\n");
    putl_code(fp,
	      "#  define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM)\n");
    putl_code(fp, "# else\n");
    putl_code(fp, "#  define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM)\n");
    putl_code(fp, "# endif\n");
    putl_code(fp, "#else\n");

    puts_code(fp, "# define YYPARSE_DECL() yyparse(");
    if (!parse_param)
	puts_code(fp, "void");
    else
    {
	param *p;
	for (p = parse_param; p; p = p->next)
	    fprintf(fp, "%s %s%s%s", p->type, p->name, p->type2,
		    p->next ? ", " : "");
    }
    putl_code(fp, ")\n");

    putl_code(fp, "#endif\n");
}
Ejemplo n.º 10
0
Archivo: output.c Proyecto: 0mp/freebsd
static void
output_ltype(FILE * fp)
{
    putc_code(fp, '\n');
    putl_code(fp, "#if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED\n");
    putl_code(fp, "/* Default: YYLTYPE is the text position type. */\n");
    putl_code(fp, "typedef struct YYLTYPE\n");
    putl_code(fp, "{\n");
    putl_code(fp, "    int first_line;\n");
    putl_code(fp, "    int first_column;\n");
    putl_code(fp, "    int last_line;\n");
    putl_code(fp, "    int last_column;\n");
    putl_code(fp, "    unsigned source;\n");
    putl_code(fp, "} YYLTYPE;\n");
    putl_code(fp, "#define YYLTYPE_IS_DECLARED 1\n");
    putl_code(fp, "#endif\n");
    putl_code(fp, "#define YYRHSLOC(rhs, k) ((rhs)[k])\n");
}