mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-18 00:33:03 +00:00
* doc/bison.texinfo (Multiple start-symbols): New.
This commit is contained in:
@@ -1,3 +1,7 @@
|
|||||||
|
2006-04-24 Akim Demaille <akim@lrde.epita.fr>
|
||||||
|
|
||||||
|
* doc/bison.texinfo (Multiple start-symbols): New.
|
||||||
|
|
||||||
2006-04-24 Akim Demaille <akim@lrde.epita.fr>
|
2006-04-24 Akim Demaille <akim@lrde.epita.fr>
|
||||||
|
|
||||||
* etc/README, etc/bench.pl: New.
|
* etc/README, etc/bench.pl: New.
|
||||||
|
|||||||
@@ -311,6 +311,7 @@ Frequently Asked Questions
|
|||||||
* How Can I Reset the Parser:: @code{yyparse} Keeps some State
|
* How Can I Reset the Parser:: @code{yyparse} Keeps some State
|
||||||
* Strings are Destroyed:: @code{yylval} Loses Track of Strings
|
* Strings are Destroyed:: @code{yylval} Loses Track of Strings
|
||||||
* Implementing Gotos/Loops:: Control Flow in the Calculator
|
* Implementing Gotos/Loops:: Control Flow in the Calculator
|
||||||
|
* Multiple start-symbols:: Factoring closely related grammars
|
||||||
* Secure? Conform?:: Is Bison @acronym{POSIX} safe?
|
* Secure? Conform?:: Is Bison @acronym{POSIX} safe?
|
||||||
* I can't build Bison:: Troubleshooting
|
* I can't build Bison:: Troubleshooting
|
||||||
* Where can I find help?:: Troubleshouting
|
* Where can I find help?:: Troubleshouting
|
||||||
@@ -7727,6 +7728,7 @@ are addressed.
|
|||||||
* How Can I Reset the Parser:: @code{yyparse} Keeps some State
|
* How Can I Reset the Parser:: @code{yyparse} Keeps some State
|
||||||
* Strings are Destroyed:: @code{yylval} Loses Track of Strings
|
* Strings are Destroyed:: @code{yylval} Loses Track of Strings
|
||||||
* Implementing Gotos/Loops:: Control Flow in the Calculator
|
* Implementing Gotos/Loops:: Control Flow in the Calculator
|
||||||
|
* Multiple start-symbols:: Factoring closely related grammars
|
||||||
* Secure? Conform?:: Is Bison @acronym{POSIX} safe?
|
* Secure? Conform?:: Is Bison @acronym{POSIX} safe?
|
||||||
* I can't build Bison:: Troubleshooting
|
* I can't build Bison:: Troubleshooting
|
||||||
* Where can I find help?:: Troubleshouting
|
* Where can I find help?:: Troubleshouting
|
||||||
@@ -7927,6 +7929,55 @@ This topic is way beyond the scope of this manual, and the reader is
|
|||||||
invited to consult the dedicated literature.
|
invited to consult the dedicated literature.
|
||||||
|
|
||||||
|
|
||||||
|
@node Multiple start-symbols
|
||||||
|
@section Multiple start-symbols
|
||||||
|
|
||||||
|
@display
|
||||||
|
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.
|
||||||
|
@end 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
|
||||||
|
@code{START_FOO} and @code{START_BAR}, and use them as switches from the
|
||||||
|
real start-symbol:
|
||||||
|
|
||||||
|
@example
|
||||||
|
%token START_FOO START_BAR;
|
||||||
|
%start start;
|
||||||
|
start: START_FOO foo
|
||||||
|
| START_BAR bar;
|
||||||
|
@end 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 @samp{%@{ ... %@}}
|
||||||
|
after the first @code{%%} is copied verbatim in the top of the generated
|
||||||
|
@code{yylex} function. Make sure a variable @code{start_token} is
|
||||||
|
available in the scanner (e.g., a global variable or using
|
||||||
|
@code{%lex-param} etc.), and use the following:
|
||||||
|
|
||||||
|
@example
|
||||||
|
/* @r{Prologue.} */
|
||||||
|
%%
|
||||||
|
%@{
|
||||||
|
if (start_token)
|
||||||
|
@{
|
||||||
|
int t = start_token;
|
||||||
|
start_token = 0;
|
||||||
|
return t;
|
||||||
|
@}
|
||||||
|
%@}
|
||||||
|
/* @r{The rules.} */
|
||||||
|
@end example
|
||||||
|
|
||||||
|
|
||||||
@node Secure? Conform?
|
@node Secure? Conform?
|
||||||
@section Secure? Conform?
|
@section Secure? Conform?
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user