[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[MAIN] output-user-code.patch
From: |
marc-alexandre autret |
Subject: |
[MAIN] output-user-code.patch |
Date: |
Tue, 28 Aug 2001 23:40:01 +0000 (GMT) |
Hi,
This patch adds the handling of %%user_code
in bison.simple. %%user_code is replaced by
the code given in the last section of a bison
grammar file.
Index: ChangeLog
===================================================================
RCS file: /cvsroot/bison/bison/ChangeLog,v
retrieving revision 1.193
diff -u -r1.193 ChangeLog
--- ChangeLog 2001/08/28 20:55:58 1.193
+++ ChangeLog 2001/08/28 21:32:15
@@ -1,5 +1,16 @@
2001-08-28 Marc Autret <address@hidden>
+ * src/output.c: Add extern declaration.
+ (output_program): Remove.
+ (output): Adjust function call.
+ Add macro insert of `user_code'
+ * src/reader.c (user_code_obstack): New.
+ (read_additionnal_code): New.
+ (reader): Clean Up and CPP-out useless code.
+ Add call to read_additionnal_code ().
+
+2001-08-28 Marc Autret <address@hidden>
+
* src/output.c (output_actions): Clean up.
(output_gram): CPP-out useless code.
* src/reader.c (reader): Clean up, CPP-out useless code.
Index: src/bison.simple
===================================================================
RCS file: /cvsroot/bison/bison/src/bison.simple,v
retrieving revision 1.58
diff -u -r1.58 bison.simple
--- src/bison.simple 2001/08/28 18:35:33 1.58
+++ src/bison.simple 2001/08/28 21:32:19
@@ -976,3 +976,5 @@
}
return 1;
}
+
+%%user_code
Index: src/output.c
===================================================================
RCS file: /cvsroot/bison/bison/src/output.c,v
retrieving revision 1.46
diff -u -r1.46 output.c
--- src/output.c 2001/08/28 20:55:58 1.46
+++ src/output.c 2001/08/28 21:32:22
@@ -126,6 +126,10 @@
struct obstack macro_obstack;
struct obstack output_obstack;
+/* Additionnal code after te last %% in garmmar file. */
+extern struct obstack user_code_obstack;
+
+
/* FIXME. */
static inline void
@@ -1018,16 +1022,6 @@
}
static void
-output_program (void)
-{
- int c;
-
- while ((c = getc (finput)) != EOF)
- obstack_1grow (&table_obstack, c);
-}
-
-
-static void
free_itemsets (void)
{
core *cp, *cptmp;
@@ -1121,8 +1115,11 @@
prepare ();
/* Copy definitions in directive. */
macro_insert ("definitions", obstack_finish (&attrs_obstack));
+ /* USER_CODE_OBSTACK is grown in reader.c after having read the
+ last %% token. We now associate it to USER_CODE directive. */
+ macro_insert ("user_code", obstack_finish (&user_code_obstack));
+
output_parser ();
- output_program ();
obstack_free (¯o_obstack, 0);
obstack_free (&output_obstack, 0);
Index: src/reader.c
===================================================================
RCS file: /cvsroot/bison/bison/src/reader.c,v
retrieving revision 1.77
diff -u -r1.77 reader.c
--- src/reader.c 2001/08/28 20:48:17 1.77
+++ src/reader.c 2001/08/28 21:32:30
@@ -66,6 +66,9 @@
static bucket *errtoken;
static bucket *undeftoken;
+
+/* After the second %%, user gives additionnal C source code. */
+struct obstack user_code_obstack;
/*===================\
@@ -1667,6 +1670,23 @@
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;
+
+ obstack_init (&user_code_obstack);
+
+ while ((c = getc (finput)) != EOF)
+ obstack_1grow (&user_code_obstack, c);
+
+ obstack_1grow (&user_code_obstack, 0);
+}
+
/*--------------------------------------------------------------.
| For named tokens, but not literal ones, define the name. The |
@@ -2016,6 +2036,8 @@
/* 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
--
Autret Marc (address@hidden)
Eleve Ingenieur en Informatique.
- [MAIN] output-user-code.patch,
marc-alexandre autret <=