summaryrefslogtreecommitdiff
path: root/output.c
diff options
context:
space:
mode:
authorDongHun Kwak <dh0128.kwak@samsung.com>2021-10-01 14:44:51 +0900
committerDongHun Kwak <dh0128.kwak@samsung.com>2021-10-01 14:44:51 +0900
commit372b8dfcdaf5efa7cc9e068843717e9621562c76 (patch)
treec048308d6627d11b2114c269c23c23c22dea7dfd /output.c
parente83b5dbc94116983df1ec99d4f02cc8640f63da5 (diff)
downloadbyacc-372b8dfcdaf5efa7cc9e068843717e9621562c76.tar.gz
byacc-372b8dfcdaf5efa7cc9e068843717e9621562c76.tar.bz2
byacc-372b8dfcdaf5efa7cc9e068843717e9621562c76.zip
Imported Upstream version 20100610upstream/20100610
Diffstat (limited to 'output.c')
-rw-r--r--output.c143
1 files changed, 131 insertions, 12 deletions
diff --git a/output.c b/output.c
index 51bf59d..73840f7 100644
--- a/output.c
+++ b/output.c
@@ -1,4 +1,4 @@
-/* $Id: output.c,v 1.24 2010/02/17 01:48:22 tom Exp $ */
+/* $Id: output.c,v 1.29 2010/06/09 21:25:18 tom Exp $ */
#include "defs.h"
@@ -532,12 +532,13 @@ pack_vector(int vector)
newmax += 200;
}
while (newmax <= loc);
+
table = (Value_t *) REALLOC(table, (unsigned)newmax * sizeof(Value_t));
- if (table == 0)
- no_space();
+ NO_SPACE(table);
+
check = (Value_t *) REALLOC(check, (unsigned)newmax * sizeof(Value_t));
- if (check == 0)
- no_space();
+ NO_SPACE(check);
+
for (l = maxtable; l < newmax; ++l)
{
table[l] = 0;
@@ -897,8 +898,7 @@ output_debug(void)
fprintf(code_file, "#define YYMAXTOKEN %d\n", max);
symnam = (const char **)MALLOC((unsigned)(max + 1) * sizeof(char *));
- if (symnam == 0)
- no_space();
+ NO_SPACE(symnam);
/* Note that it is not necessary to initialize the element */
/* symnam[max]. */
@@ -1099,8 +1099,9 @@ output_stype(void)
{
if (!unionized && ntags == 0)
{
- outline += 3;
- fprintf(code_file, "#ifndef YYSTYPE\ntypedef int YYSTYPE;\n#endif\n");
+ outline += 5;
+ fprintf(code_file,
+ "\n#ifndef YYSTYPE\ntypedef int YYSTYPE;\n#endif\n\n");
}
}
@@ -1178,6 +1179,122 @@ output_semantic_actions(void)
}
static void
+output_parse_decl(void)
+{
+ ++outline;
+ fprintf(code_file, "/* compatibility with bison */\n");
+ ++outline;
+ fprintf(code_file, "#ifdef YYPARSE_PARAM\n");
+ ++outline;
+ fprintf(code_file, "/* compatibility with FreeBSD */\n");
+ ++outline;
+ fprintf(code_file, "# ifdef YYPARSE_PARAM_TYPE\n");
+ ++outline;
+ fprintf(code_file, "# define YYPARSE_DECL() "
+ "yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM)\n");
+ ++outline;
+ fprintf(code_file, "# else\n");
+ ++outline;
+ fprintf(code_file, "# define YYPARSE_DECL() "
+ "yyparse(void *YYPARSE_PARAM)\n");
+ ++outline;
+ fprintf(code_file, "# endif\n");
+ ++outline;
+ fprintf(code_file, "#else\n");
+ ++outline;
+ fprintf(code_file, "# define YYPARSE_DECL() yyparse(");
+ if (!parse_param)
+ fprintf(code_file, "void");
+ else
+ {
+ param *p;
+ for (p = parse_param; p; p = p->next)
+ fprintf(code_file, "%s %s%s%s", p->type, p->name, p->type2,
+ p->next ? ", " : "");
+ }
+ fprintf(code_file, ")\n");
+ outline += 2;
+ fprintf(code_file, "#endif\n\n");
+}
+
+static void
+output_lex_decl(void)
+{
+ ++outline;
+ fprintf(code_file, "/* Parameters sent to lex. */\n");
+ ++outline;
+ fprintf(code_file, "#ifdef YYLEX_PARAM\n");
+ if (pure_parser)
+ {
+ ++outline;
+ fprintf(code_file, "# define YYLEX_DECL() yylex(YYSTYPE *yylval, "
+ "void *YYLEX_PARAM)\n");
+ ++outline;
+ fprintf(code_file, "# define YYLEX yylex(&yylval, YYLEX_PARAM)\n");
+ }
+ else
+ {
+ ++outline;
+ fprintf(code_file,
+ "# define YYLEX_DECL() yylex(void *YYLEX_PARAM)\n");
+ ++outline;
+ fprintf(code_file, "# define YYLEX yylex(YYLEX_PARAM)\n");
+ }
+ ++outline;
+ fprintf(code_file, "#else\n");
+ if (pure_parser && lex_param)
+ {
+ param *p;
+ fprintf(code_file, "# define YYLEX_DECL() yylex(YYSTYPE *yylval, ");
+ for (p = lex_param; p; p = p->next)
+ fprintf(code_file, "%s %s%s%s", p->type, p->name, p->type2,
+ p->next ? ", " : "");
+ ++outline;
+ fprintf(code_file, ")\n");
+
+ fprintf(code_file, "# define YYLEX yylex(&yylval, ");
+ for (p = lex_param; p; p = p->next)
+ fprintf(code_file, "%s%s", p->name, p->next ? ", " : "");
+ ++outline;
+ fprintf(code_file, ")\n");
+ }
+ else if (pure_parser)
+ {
+ ++outline;
+ fprintf(code_file, "# define YYLEX_DECL() yylex(YYSTYPE *yylval)\n");
+
+ ++outline;
+ fprintf(code_file, "# define YYLEX yylex(&yylval)\n");
+ }
+ else if (lex_param)
+ {
+ param *p;
+ fprintf(code_file, "# define YYLEX_DECL() yylex(");
+ for (p = lex_param; p; p = p->next)
+ fprintf(code_file, "%s %s%s%s", p->type, p->name, p->type2,
+ p->next ? ", " : "");
+ ++outline;
+ fprintf(code_file, ")\n");
+
+ fprintf(code_file, "# define YYLEX yylex(");
+ for (p = lex_param; p; p = p->next)
+ fprintf(code_file, "%s%s", p->name, p->next ? ", " : "");
+ ++outline;
+ fprintf(code_file, ")\n");
+ }
+ else
+ {
+ ++outline;
+ fprintf(code_file, "# define YYLEX_DECL() yylex(void)\n");
+
+ ++outline;
+ fprintf(code_file, "# define YYLEX yylex()\n");
+ }
+ outline += 2;
+ fprintf(code_file, "#endif\n\n");
+}
+
+static void
free_itemsets(void)
{
core *cp, *next;
@@ -1223,15 +1340,18 @@ output(void)
free_shifts();
free_reductions();
output_prefix(output_file);
- write_section(xdecls);
+ output_pure_parser();
output_stored_text();
+ output_stype();
+ output_parse_decl();
+ output_lex_decl();
+ write_section(xdecls);
output_defines();
output_rule_data();
output_yydefred();
output_actions();
free_parser();
output_debug();
- output_stype();
if (rflag)
{
output_prefix(code_file);
@@ -1239,7 +1359,6 @@ output(void)
write_section(tables);
}
write_section(hdr_defs);
- output_pure_parser();
if (!pure_parser)
{
write_section(hdr_vars);