* src/reader.c (copy_at): Typo: s/yylloc/yyloc/.
* src/files.c (fattrs): Remove.
(attrs_obstack): New.
Adjust all dependencies.
(done): If SEMANTIC_PARSER, dump attrs_obstack into attrsfile.
+2000-11-01 Akim Demaille <akim@epita.fr>
+
+ Change each use of `fattrs' into a use of `attrs_obstack'.
+
+ * src/reader.c (copy_at): Typo: s/yylloc/yyloc/.
+ * src/files.c (fattrs): Remove.
+ (attrs_obstack): New.
+ Adjust all dependencies.
+ (done): If SEMANTIC_PARSER, dump attrs_obstack into attrsfile.
+
2000-11-01 Akim Demaille <akim@epita.fr>
Introduce obstacks.
FILE *foutput = NULL;
FILE *fdefines = NULL;
FILE *ftable = NULL;
-FILE *fattrs = NULL;
FILE *fguard = NULL;
FILE *fparser = NULL;
struct obstack action_obstack;
+struct obstack attrs_obstack;
/* File name specified with -o for the output file, or 0 if no -o. */
char *spec_outfile;
static char *tabfile;
static char *guardfile;
static char *actfile;
-static char *tmpattrsfile;
static char *tmptabfile;
static char *tmpdefsfile;
}
#ifdef MSDOS
- tmpattrsfile = mktemp (stringappend (tmp_base, tmp_len, "atXXXXXX"));
tmptabfile = mktemp (stringappend (tmp_base, tmp_len, "taXXXXXX"));
tmpdefsfile = mktemp (stringappend (tmp_base, tmp_len, "deXXXXXX"));
#else
- tmpattrsfile = mktemp (stringappend (tmp_base, tmp_len, "attrs.XXXXXX"));
tmptabfile = mktemp (stringappend (tmp_base, tmp_len, "tab.XXXXXX"));
tmpdefsfile = mktemp (stringappend (tmp_base, tmp_len, "defs.XXXXXX"));
#endif /* not MSDOS */
- fattrs = xfopen (tmpattrsfile, "w+");
ftable = xfopen (tmptabfile, "w+");
if (defines_flag)
}
#if !(defined (MSDOS) || (defined(_WIN32) && !defined(__CYGWIN32__)))
- unlink (tmpattrsfile);
unlink (tmptabfile);
unlink (tmpdefsfile);
#endif /* MSDOS || (_WIN32 && !__CYGWIN32__) */
#endif /* not MSDOS */
#endif /* not VMS */
- /* Setup the action obstack. */
+ /* Initialize the obstacks. */
obstack_init (&action_obstack);
+ obstack_init (&attrs_obstack);
}
void
open_extra_files (void)
{
- FILE *ftmp;
int c;
char *filename;
-#ifdef MSDOS
- char *cp;
-#endif
xfclose (fparser);
{
filename = (char *) getenv ("BISON_HAIRY");
#ifdef MSDOS
- /* File doesn't exist in current directory; try in INIT directory. */
- cp = getenv ("INIT");
- if (filename == 0 && cp != NULL)
- {
- filename = XMALLOC (char, strlen (cp) + strlen (PFILE1) + 2);
- strcpy (filename, cp);
- cp = filename + strlen (filename);
- *cp++ = '/';
- strcpy (cp, PFILE1);
- }
+ {
+ /* File doesn't exist in current directory; try in INIT
+ directory. */
+ char *cp = getenv ("INIT");
+ if (filename == 0 && cp != NULL)
+ {
+ filename = XMALLOC (char, strlen (cp) + strlen (PFILE1) + 2);
+ strcpy (filename, cp);
+ cp = filename + strlen (filename);
+ *cp++ = '/';
+ strcpy (cp, PFILE1);
+ }
+ }
#endif
fparser = xfopen (filename ? filename : PFILE1, "r");
}
- /* JF change from inline attrs file to separate one */
- ftmp = xfopen (attrsfile, "w");
- rewind (fattrs);
- while ((c = getc (fattrs)) != EOF) /* Thank god for buffering */
- putc (c, ftmp);
- xfclose (fattrs);
- fattrs = ftmp;
-
fguard = xfopen (guardfile, "w");
-
}
void
done (void)
{
- xfclose (fattrs);
xfclose (fguard);
xfclose (finput);
xfclose (fparser);
}
}
+ /* If we output only the table, dump the actions in ACTION_OBSTACK.
+ */
if (no_parser_flag)
{
FILE *faction = xfopen (actfile, "w");
size_t size = obstack_object_size (&action_obstack);
fwrite (obstack_finish (&action_obstack), 1, size, faction);
- fclose (faction);
+ xfclose (faction);
}
+
+ /* If we produced a semantic parser ATTRS_OBSTACK must be dumped
+ into its own file, ATTTRSFILE. */
+ if (semantic_parser)
+ {
+ FILE *fattrs = xfopen (attrsfile, "w");
+ size_t size = obstack_object_size (&attrs_obstack);
+ fwrite (obstack_finish (&attrs_obstack), 1, size, fattrs);
+ xfclose (fattrs);
+ }
+
#if defined (VMS) & !defined (__VMS_POSIX)
- if (fattrs)
- delete (tmpattrsfile);
if (ftable)
delete (tmptabfile);
/* Don't call exit again, we're in atexit ().
sys$exit(SS$_ABORT); */
#else
#if (defined (MSDOS) || (defined(_WIN32) && !defined(__CYGWIN32__)))
- if (tmpattrsfile)
- unlink (tmpattrsfile);
if (tmptabfile)
unlink (tmptabfile);
if (tmpdefsfile)
extern FILE *foutput; /* optionally output messages describing the actions taken */
extern FILE *fdefines; /* optionally output #define's for token numbers. */
extern FILE *ftable; /* output the tables and the parser */
-extern FILE *fattrs; /* if semantic parser, output a .h file that defines YYSTYPE */
/* and also contains all the %{ ... %} definitions. */
extern FILE *fguard; /* if semantic parser, output yyguard, containing all the guard code */
extern FILE *fparser; /* read the parser to copy into ftable */
/* Output all the action code; precise form depends on which parser. */
extern struct obstack action_obstack;
+/* If semantic parser, output a .h file that defines YYSTYPE */
+extern struct obstack attrs_obstack;
extern char *infile;
extern int lineno;
int c;
/* output_token_defines(ftable); / * JF put out token defines FIRST */
- if (!semantic_parser) /* JF Put out other stuff */
+
+ /* If using a simple parser the definition of YYSTYPE are put into
+ FTABLE. */
+ if (!semantic_parser)
{
- rewind (fattrs);
- while ((c = getc (fattrs)) != EOF)
- putc (c, ftable);
+ size_t size = obstack_object_size (&attrs_obstack);
+ fwrite (obstack_finish (&attrs_obstack), 1, size, ftable);
}
reader_output_yylsp (ftable);
if (debug_flag)
if (fout)
fprintf (fout, "yyloc");
if (oout)
- obstack_grow_literal_string (oout, "yylloc");
+ obstack_grow_literal_string (oout, "yyloc");
locations_flag = 1;
}
else if (isdigit (c) || c == '-')
int after_percent;
if (!no_lines_flag)
- fprintf (fattrs, "#line %d \"%s\"\n", lineno, infile);
+ obstack_fgrow2 (&attrs_obstack, "#line %d \"%s\"\n", lineno, infile);
after_percent = 0;
switch (c)
{
case '\n':
- putc (c, fattrs);
+ obstack_1grow (&attrs_obstack, c);
lineno++;
break;
case '\'':
case '"':
- copy_string (finput, fattrs, 0, c);
+ copy_string (finput, 0, &attrs_obstack, c);
break;
case '/':
- copy_comment (finput, fattrs, 0);
+ copy_comment (finput, 0, &attrs_obstack);
break;
case EOF:
fatal ("%s", _("unterminated `%{' definition"));
default:
- putc (c, fattrs);
+ obstack_1grow (&attrs_obstack, c);
}
c = getc (finput);
{
if (c == '}')
return;
- putc ('%', fattrs);
+ obstack_1grow (&attrs_obstack, '%');
}
after_percent = 0;
-
}
-
}
-/*-------------------------------------------------------------------.
-| Copy the union declaration into fattrs (and fdefines), where it is |
-| made into the definition of YYSTYPE, the type of elements of the |
-| parser value stack. |
-`-------------------------------------------------------------------*/
+/*--------------------------------------------------------------.
+| Copy the union declaration into ATTRS_OBSTACK (and fdefines), |
+| where it is made into the definition of YYSTYPE, the type of |
+| elements of the parser value stack. |
+`--------------------------------------------------------------*/
static void
parse_union_decl (void)
typed = 1;
if (!no_lines_flag)
- fprintf (fattrs, "\n#line %d \"%s\"\n", lineno, infile);
+ obstack_fgrow2 (&attrs_obstack, "\n#line %d \"%s\"\n", lineno, infile);
else
- fprintf (fattrs, "\n");
+ obstack_1grow (&attrs_obstack, '\n');
- fprintf (fattrs, "typedef union");
+ obstack_grow_literal_string (&attrs_obstack, "typedef union");
if (fdefines)
fprintf (fdefines, "typedef union");
while (c != EOF)
{
- putc (c, fattrs);
+ obstack_1grow (&attrs_obstack, c);
if (fdefines)
putc (c, fdefines);
break;
case '/':
- copy_comment2 (finput, fattrs, fdefines, 0);
+ copy_comment2 (finput, 0, fdefines, &attrs_obstack);
break;
case '{':
count--;
if (count <= 0)
{
- fprintf (fattrs, " YYSTYPE;\n");
+ obstack_grow_literal_string (&attrs_obstack, " YYSTYPE;\n");
if (fdefines)
fprintf (fdefines, " YYSTYPE;\n");
/* JF don't choke on trailing semi */
/*----------------------------------------------------------------.
| Read from finput until `%%' is seen. Discard the `%%'. Handle |
| any `%' declarations, and copy the contents of any `%{ ... %}' |
-| groups to fattrs. |
+| groups to ATTRS_OBSTACK. |
`----------------------------------------------------------------*/
static void
/* We used to use `unsigned long' as YYSTYPE on MSDOS,
but it seems better to be consistent.
Most programs should declare their own type anyway. */
- fprintf (fattrs, "#ifndef YYSTYPE\n#define YYSTYPE int\n#endif\n");
+ obstack_grow_literal_string (&attrs_obstack,
+ "#ifndef YYSTYPE\n#define YYSTYPE int\n#endif\n");
if (fdefines)
fprintf (fdefines, "#ifndef YYSTYPE\n#define YYSTYPE int\n#endif\n");
}
sprintf (buf, Format, Arg1); \
obstack_grow (Obs, buf, strlen (buf)); \
} while (0)
+
+#define obstack_fgrow2(Obs, Format, Arg1, Arg2) \
+do { \
+ char buf[4096]; \
+ sprintf (buf, Format, Arg1, Arg2); \
+ obstack_grow (Obs, buf, strlen (buf)); \
+} while (0)