-/* $Id: reader.c,v 1.87 2021/03/28 17:58:37 tom Exp $ */
+/* $Id: reader.c,v 1.91 2022/01/09 18:04:58 tom Exp $ */
#include "defs.h"
/* this is a hard limit, but seems more than adequate */
#define MAXARGS 20
+#define begin_case(f,n) fprintf(f, "case %d:\n", (int)(n))
+
+#define end_case(f) \
+ fprintf(f, "\n"); \
+ fprintf_lineno(f, 1, ""); \
+ fprintf(f, "break;\n")
+
static void start_rule(bucket *bp, int s_lineno);
#if defined(YYBTYACC)
static void copy_initial_action(void);
code_mstr = msnew();
}
cline++;
- msprintf(code_mstr, line_format, lineno, input_file_name);
+ if (!lflag)
+ msprintf(code_mstr, line_format, lineno, input_file_name);
for (;;)
{
c = *cptr++;
if (line == NULL)
unterminated_text(&a);
}
- if (!lflag)
- fprintf(f, line_format, lineno, input_file_name);
+ fprintf_lineno(f, lineno, input_file_name);
loop:
c = *cptr++;
puts_both("#ifndef YYSTYPE_IS_DECLARED\n");
puts_both("#define YYSTYPE_IS_DECLARED 1\n");
- if (!lflag)
- fprintf(text_file, line_format, lineno, input_file_name);
+ fprintf_lineno(text_file, lineno, input_file_name);
puts_both("typedef union YYSTYPE");
depth = 0;
{
int j;
- offsets = TMALLOC(Value_t, maxoffset + 1);
+ offsets = TCMALLOC(Value_t, maxoffset + 1);
NO_SPACE(offsets);
for (j = 0, i++; i < nitems; i++)
{
int j;
- offsets = TMALLOC(Value_t, maxoffset + 1);
+ offsets = TCMALLOC(Value_t, maxoffset + 1);
NO_SPACE(offsets);
for (j = 0, i++; i < nitems; i++)
rule = nrules;
insert_arg_cache(code, rule);
trialaction = 1; /* arg rules always run in trial mode */
- fprintf(f, "case %d:\n", rule - 2);
- if (!lflag)
- fprintf(f, line_format, line_number, input_file_name);
- fprintf(f, "%s;\n", code);
- fprintf(f, "break;\n");
+ begin_case(f, rule - 2);
+ fprintf_lineno(f, line_number, input_file_name);
+ fprintf(f, "%s;", code);
+ end_case(f);
insert_empty_rule();
plhs[rule]->tag = cache_tag(tag, strlen(tag));
plhs[rule]->class = ARGUMENT;
trialaction = (*cptr == L_BRAC);
#endif
- fprintf(f, "case %d:\n", nrules - 2);
+ begin_case(f, nrules - 2);
#if defined(YYBTYACC)
if (backtrack)
{
fprintf(f, " if (!yytrial)\n");
}
#endif
- if (!lflag)
- fprintf(f, line_format, lineno, input_file_name);
+ fprintf_lineno(f, lineno, input_file_name);
if (*cptr == '=')
++cptr;
else if (i > maxoffset)
{
dollar_warning(d_lineno, i);
- fprintf(f, "yystack.l_mark[%d].%s", i - maxoffset, tag);
+ fprintf(f, "yystack.l_mark[%ld].%s",
+ (long)(i - maxoffset), tag);
}
else if (offsets)
- fprintf(f, "yystack.l_mark[%d].%s", offsets[i], tag);
+ fprintf(f, "yystack.l_mark[%ld].%s",
+ (long)offsets[i], tag);
FREE(d_line);
goto loop;
}
tag = rhs[offsets[i]]->tag;
if (tag == 0)
untyped_rhs(i, rhs[offsets[i]]->name);
- fprintf(f, "yystack.l_mark[%d].%s", offsets[i], tag);
+ fprintf(f, "yystack.l_mark[%ld].%s", (long)offsets[i], tag);
}
else
{
else if (i > maxoffset)
{
dollar_warning(lineno, i);
- fprintf(f, "yystack.l_mark[%d]", i - maxoffset);
+ fprintf(f, "yystack.l_mark[%ld]", (long)(i - maxoffset));
}
else if (offsets)
- fprintf(f, "yystack.l_mark[%d]", offsets[i]);
+ fprintf(f, "yystack.l_mark[%ld]", (long)offsets[i]);
}
goto loop;
}
if (c == L_CURL && !haveyyval)
{
fprintf(f, " if (!yytrial)\n");
- if (!lflag)
- fprintf(f, line_format, lineno, input_file_name);
+ fprintf_lineno(f, lineno, input_file_name);
trialaction = 0;
goto loop;
}
- fprintf(f, "\nbreak;\n");
+ end_case(f);
FREE(a.a_line);
if (maxoffset > 0)
FREE(offsets);
case ';':
if (depth > 0)
goto loop;
- fprintf(f, "\nbreak;\n");
+ end_case(f);
free(a.a_line);
if (maxoffset > 0)
FREE(offsets);
if (c == L_CURL && !haveyyval)
{
fprintf(f, " if (!yytrial)\n");
- if (!lflag)
- fprintf(f, line_format, lineno, input_file_name);
+ fprintf_lineno(f, lineno, input_file_name);
goto loop;
}
}
#endif
- fprintf(f, "\nbreak;\n");
+ end_case(f);
free(a.a_line);
if (maxoffset > 0)
FREE(offsets);
|| c == '$'
|| c == '\''
|| c == '"')
+ {
add_symbol();
+ }
+ else if (c == L_CURL || c == '='
#if defined(YYBTYACC)
- else if (c == L_CURL || c == '=' || (backtrack && c == L_BRAC))
-#else
- else if (c == L_CURL || c == '=')
+ || (backtrack && c == L_BRAC)
#endif
+ )
+ {
copy_action();
+ }
else if (c == '|')
{
end_rule();
}
else
{ /* replace "$$" with "(*val)[.tag]" in destructor code */
+ char *destructor_source = symbol_destructor[i];
symbol_destructor[i]
- = process_destructor_XX(symbol_destructor[i], tag);
+ = process_destructor_XX(destructor_source, tag);
+ FREE(destructor_source);
}
}
/* 'symbol_type_tag[]' elements are freed by 'free_tags()' */