bison-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[MAIN] several-skels.patch


From: marc-alexandre autret
Subject: [MAIN] several-skels.patch
Date: Thu, 30 Aug 2001 02:56:26 +0000 (GMT)

Hi,

Here is a patch which gives an idea about the
method we can use to output informations in
several files of the same skeleton.

ex:

in bison.simple, we add

header.h
stack.h
%
[........]

and all macros in header.h and stack.h will be replaced and the files
are saved at the bison working place.
(it's only an overview for the moment).


Index: ChangeLog
===================================================================
RCS file: /cvsroot/bison/bison/ChangeLog,v
retrieving revision 1.196
diff -u -r1.196 ChangeLog
--- ChangeLog   2001/08/30 00:44:14     1.196
+++ ChangeLog   2001/08/30 00:47:57
@@ -1,5 +1,18 @@
 2001-08-30  Marc Autret  <address@hidden>
 
+       These new changes allow us to have skeletons written in
+       several files. At the begining of the `master skeleton',
+       we can detail the other files to use. This section ends 
+       by a `%' character.
+       
+       * src/bison.simple: Add '%' at the begining.
+       * src/output.c (output): CPP-out useless code.
+       (macro_replace_in_skeleton): New.
+       (output_parser): Use it.
+       (output_subskeleton_parser): New.
+
+2001-08-30  Marc Autret  <address@hidden>
+
        * src/reader.c (parse_skel_decl): New.
        (read_declarations): Add case `tok_skel', call parse_skel_decl (). 
        * src/lex.h (token_t): New token `tok_skel'.
Index: src/bison.simple
===================================================================
RCS file: /cvsroot/bison/bison/src/bison.simple,v
retrieving revision 1.59
diff -u -r1.59 bison.simple
--- src/bison.simple    2001/08/29 14:17:00     1.59
+++ src/bison.simple    2001/08/30 00:48:00
@@ -1,3 +1,4 @@
+%
 /* -*- C -*- */
 
 /* A Bison parser, made from %%filename
Index: src/output.c
===================================================================
RCS file: /cvsroot/bison/bison/src/output.c,v
retrieving revision 1.47
diff -u -r1.47 output.c
--- src/output.c        2001/08/29 14:17:00     1.47
+++ src/output.c        2001/08/30 00:48:02
@@ -952,24 +952,13 @@
 `------------------------------------------*/
 
 static void
-output_parser (void)
+macro_replace_in_skeleton (FILE *fskel, struct obstack *out_obstack)
 {
   int c;
-  FILE *fskel;
   size_t line;
   int actions_dumped = 0;
-
-  /* Loop over lines in the standard parser file.  */
-  if (!skeleton)
-    {
-      if (semantic_parser)
-       skeleton = skeleton_find ("BISON_HAIRY", BISON_HAIRY);
-      else
-       skeleton = skeleton_find ("BISON_SIMPLE", BISON_SIMPLE);
-    }
-  fskel = xfopen (skeleton, "r");
 
-  /* New output code. */
+ /* New output code. */
   line = 1;
   c = getc (fskel);
   while (c != EOF)
@@ -978,7 +967,7 @@
        {
          if (c == '\n')
            ++line;
-         obstack_1grow (&table_obstack, c);
+         obstack_1grow (out_obstack, c);
          c = getc (fskel);
        }
       else if ((c = getc (fskel)) == '%')
@@ -994,27 +983,105 @@
          macro_key = obstack_finish (&macro_obstack);
          macro_value = macro_find (macro_key);
          if (macro_value)
-           obstack_sgrow (&table_obstack, macro_value);
+           obstack_sgrow (out_obstack, macro_value);
          else if (!strcmp (macro_key, "line"))
-           obstack_fgrow1 (&table_obstack, "%d", line + 1);
+           obstack_fgrow1 (out_obstack, "%d", line + 1);
          else if (!strcmp (macro_key, "action"))
            {
              size_t size = obstack_object_size (&action_obstack);
-             obstack_grow (&table_obstack, 
-                           obstack_finish (&action_obstack), size);
+             obstack_grow (out_obstack, 
+                           obstack_finish (&action_obstack), size); /* FIXME.  
*/
            }
          else
            {
-             obstack_sgrow (&table_obstack, "%%");
-             obstack_sgrow (&table_obstack, macro_key);
+             obstack_sgrow (out_obstack, "%%");
+             obstack_sgrow (out_obstack, macro_key);
            }
        }
+      else
+       obstack_1grow (out_obstack, '%');
+    }
+}
+
+static void
+output_subskeleton_parser (const char *skel_filename)
+{
+  FILE *subskel;
+  FILE *fout;
+  struct obstack oout;
+  size_t size;
+  
+  obstack_init (&oout);
+  subskel = xfopen (skel_filename, "r");
+  
+  macro_replace_in_skeleton (subskel, &oout);
+  xfclose (subskel);
+
+  size = strlen (skel_filename);
+  for (; size && (skel_filename[size] != '/'); size--)
+    ;
+  size += (skel_filename[size] == '/');
+  
+  fout = xfopen (skel_filename + size, "w");
+  size = obstack_object_size (&oout);
+  fwrite (obstack_finish (&oout), 1, size, fout);
+  xfclose (fout);
+}
+
+static void
+output_parser (void)
+{
+  FILE *fskel;
+  char ch;
+  char buff[64];
+  int i;
+
+  /* Loop over lines in the standard parser file.  */
+  if (!skeleton)
+    {
+      if (semantic_parser)
+       skeleton = skeleton_find ("BISON_HAIRY", BISON_HAIRY);
       else
-       obstack_1grow (&table_obstack, '%');
+       skeleton = skeleton_find ("BISON_SIMPLE", BISON_SIMPLE);
     }
+
+  fskel = xfopen (skeleton, "r");
+  
+  /* In the first lines of the parser skeleton, we have the possible
+     names of additional skeleton files. This part is ended by a %.
+     We can use it in a filename by escaping it.  */
+  ch = getc (fskel);
+  for (i = 0; isprint (ch) || (ch == '\n'); i++)
+    {
+      if (ch == '%')
+       break;
+      
+      if (ch == '\\')
+       {
+         if ((ch == getc (fskel)) == EOF)
+           fatal (_("Premature EOF")); /* Translation.  */
+         if (!isprint (ch))
+           break;
+       }
 
-  /* End. */
-  xfclose (fskel);
+      if (ch == '\n')
+       {
+         buff[i] = '\0';
+         output_subskeleton_parser (buff);
+         i = 0;
+       }
+      else
+       buff[i] = ch;
+      
+      ch = getc (fskel);
+    }
+  
+  if (ch != '%')
+    /* complain bad skeleton entry.  */
+    ;
+  
+  macro_replace_in_skeleton (fskel, &table_obstack);
+  xfclose (fskel);  
 }
 
 static void
@@ -1095,7 +1162,9 @@
 {
   obstack_init (&output_obstack);
 
-  /* reader_output_yylsp (&table_obstack); */
+#if 0
+  reader_output_yylsp (&table_obstack);
+#endif
   free_itemsets ();
 
   output_token_translations ();
@@ -1107,7 +1176,9 @@
   output_rule_data ();
   output_actions ();
 
-  /* if (!no_parser_flag) */
+#if 0
+  if (!no_parser_flag)
+#endif
   prepare ();
   /* Copy definitions in directive.  */
   macro_insert ("definitions", obstack_finish (&attrs_obstack));


-- 
Autret Marc (address@hidden)
Eleve Ingenieur en Informatique.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]