Index: ChangeLog
from Akim Demaille <[EMAIL PROTECTED]>
* doc/bison.texinfo (Multiple start-symbols): New.
+2006-04-24 Akim Demaille <[EMAIL PROTECTED]>
+
* etc/README, etc/bench.pl: New.
2006-04-03 Akim Demaille <[EMAIL PROTECTED]>
Index: doc/bison.texinfo
===================================================================
RCS file: /cvsroot/bison/bison/doc/bison.texinfo,v
retrieving revision 1.184
diff -u -r1.184 bison.texinfo
--- doc/bison.texinfo 17 Mar 2006 07:59:20 -0000 1.184
+++ doc/bison.texinfo 24 Apr 2006 09:45:35 -0000
@@ -311,6 +311,7 @@
* How Can I Reset the Parser:: @code{yyparse} Keeps some State
* Strings are Destroyed:: @code{yylval} Loses Track of Strings
* Implementing Gotos/Loops:: Control Flow in the Calculator
+* Multiple start-symbols:: Factoring closely related grammars
* Secure? Conform?:: Is Bison @acronym{POSIX} safe?
* I can't build Bison:: Troubleshooting
* Where can I find help?:: Troubleshouting
@@ -7727,6 +7728,7 @@
* How Can I Reset the Parser:: @code{yyparse} Keeps some State
* Strings are Destroyed:: @code{yylval} Loses Track of Strings
* Implementing Gotos/Loops:: Control Flow in the Calculator
+* Multiple start-symbols:: Factoring closely related grammars
* Secure? Conform?:: Is Bison @acronym{POSIX} safe?
* I can't build Bison:: Troubleshooting
* Where can I find help?:: Troubleshouting
@@ -7927,6 +7929,55 @@
invited to consult the dedicated literature.
[EMAIL PROTECTED] Multiple start-symbols
[EMAIL PROTECTED] Multiple start-symbols
+
[EMAIL PROTECTED]
+I have several closely related grammars, and I would like to share their
+implementations. In fact, I could use a single grammar but with
+multiple entry points.
[EMAIL PROTECTED] display
+
+Bison does not support multiple start-symbols, but there is a very
+simple means to simulate them. If @code{foo} and @code{bar} are the two
+pseudo start-symbols, then introduce two new tokens, say
[EMAIL PROTECTED] and @code{START_BAR}, and use them as switches from the
+real start-symbol:
+
[EMAIL PROTECTED]
+%token START_FOO START_BAR;
+%start start;
+start: START_FOO foo
+ | START_BAR bar;
[EMAIL PROTECTED] example
+
+These tokens prevents the introduction of new conflicts. As far as the
+parser goes, that is all that is needed.
+
+Now the difficult part is ensuring that the scanner will send these
+tokens first. If your scanner is hand-written, that should be
+straightforward. If your scanner is generated by Lex, them there is
+simple means to do it: recall that anything between @[EMAIL PROTECTED] ...
[EMAIL PROTECTED]
+after the first @code{%%} is copied verbatim in the top of the generated
[EMAIL PROTECTED] function. Make sure a variable @code{start_token} is
+available in the scanner (e.g., a global variable or using
[EMAIL PROTECTED] etc.), and use the following:
+
[EMAIL PROTECTED]
+ /* @r{Prologue.} */
+%%
[EMAIL PROTECTED]
+ if (start_token)
+ @{
+ int t = start_token;
+ start_token = 0;
+ return t;
+ @}
[EMAIL PROTECTED]
+ /* @r{The rules.} */
[EMAIL PROTECTED] example
+
+
@node Secure? Conform?
@section Secure? Conform?