From: Marc Autret Date: Wed, 29 Aug 2001 14:17:00 +0000 (+0000) Subject: * src/bison.simple: Add %%user_code directive at the end. X-Git-Tag: pre-merge-of-1-29-branch~46 X-Git-Url: https://git.saurik.com/bison.git/commitdiff_plain/ff48177d2514d8ba381852e4d1f50b98ef3cd763?ds=sidebyside * src/bison.simple: Add %%user_code directive at the end. * src/reader.c (read_additionnal_code): New. (reader): Use it. * src/output.c (output_program): Remove. (output): Update. --- diff --git a/ChangeLog b/ChangeLog index cb02468a..d35daa29 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2001-08-29 Marc Autret + + * src/bison.simple: Add %%user_code directive at the end. + * src/reader.c (read_additionnal_code): New. + (reader): Use it. + * src/output.c (output_program): Remove. + (output): Update. + 2001-08-28 Marc Autret * src/output.c (output_actions): Clean up. diff --git a/src/bison.simple b/src/bison.simple index 700a9edb..d6268630 100644 --- a/src/bison.simple +++ b/src/bison.simple @@ -976,3 +976,6 @@ yyabortlab: } return 1; } + +%%user_code + diff --git a/src/output.c b/src/output.c index b58f0ec0..21711cb1 100644 --- a/src/output.c +++ b/src/output.c @@ -1017,16 +1017,6 @@ output_parser (void) xfclose (fskel); } -static void -output_program (void) -{ - int c; - - while ((c = getc (finput)) != EOF) - obstack_1grow (&table_obstack, c); -} - - static void free_itemsets (void) { @@ -1122,7 +1112,6 @@ output (void) /* Copy definitions in directive. */ macro_insert ("definitions", obstack_finish (&attrs_obstack)); output_parser (); - output_program (); obstack_free (¯o_obstack, 0); obstack_free (&output_obstack, 0); diff --git a/src/reader.c b/src/reader.c index 282611d7..8fa3dfe8 100644 --- a/src/reader.c +++ b/src/reader.c @@ -1667,6 +1667,25 @@ readgram (void) ntokens = nsyms - nvars; } + +/* At the end of the grammar file, some C source code must + be stored. It is going to be associated to the user_code + directive. */ +static void +read_additionnal_code (void) +{ + char c; + struct obstack uc_obstack; + + obstack_init (&uc_obstack); + + while ((c = getc (finput)) != EOF) + obstack_1grow (&uc_obstack, c); + + obstack_1grow (&uc_obstack, 0); + macro_insert ("user_code", obstack_finish (&uc_obstack)); +} + /*--------------------------------------------------------------. | For named tokens, but not literal ones, define the name. The | @@ -2016,6 +2035,8 @@ reader (void) /* Read in the grammar, build grammar in list form. Write out guards and actions. */ readgram (); + /* Some C code is given at the end of the grammar file. */ + read_additionnal_code (); /* Now we know whether we need the line-number stack. If we do, write its type into the .tab.h file. */ #if 0