3163 |
@subsection A Pure (Reentrant) Parser |
@subsection A Pure (Reentrant) Parser |
3164 |
@cindex reentrant parser |
@cindex reentrant parser |
3165 |
@cindex pure parser |
@cindex pure parser |
3166 |
@findex %pure_parser |
@findex %pure-parser |
3167 |
|
|
3168 |
A @dfn{reentrant} program is one which does not alter in the course of |
A @dfn{reentrant} program is one which does not alter in the course of |
3169 |
execution; in other words, it consists entirely of @dfn{pure} (read-only) |
execution; in other words, it consists entirely of @dfn{pure} (read-only) |
3179 |
including @code{yylval} and @code{yylloc}.) |
including @code{yylval} and @code{yylloc}.) |
3180 |
|
|
3181 |
Alternatively, you can generate a pure, reentrant parser. The Bison |
Alternatively, you can generate a pure, reentrant parser. The Bison |
3182 |
declaration @code{%pure_parser} says that you want the parser to be |
declaration @code{%pure-parser} says that you want the parser to be |
3183 |
reentrant. It looks like this: |
reentrant. It looks like this: |
3184 |
|
|
3185 |
@example |
@example |
3186 |
%pure_parser |
%pure-parser |
3187 |
@end example |
@end example |
3188 |
|
|
3189 |
The result is that the communication variables @code{yylval} and |
The result is that the communication variables @code{yylval} and |
3270 |
Specify a prefix to use for all Bison output file names. The names are |
Specify a prefix to use for all Bison output file names. The names are |
3271 |
chosen as if the input file were named @file{@var{prefix}.y}. |
chosen as if the input file were named @file{@var{prefix}.y}. |
3272 |
|
|
3273 |
@c @item %header_extension |
@c @item %header-extension |
3274 |
@c Specify the extension of the parser header file generated when |
@c Specify the extension of the parser header file generated when |
3275 |
@c @code{%define} or @samp{-d} are used. |
@c @code{%define} or @samp{-d} are used. |
3276 |
@c |
@c |
3277 |
@c For example, a grammar file named @file{foo.ypp} and containing a |
@c For example, a grammar file named @file{foo.ypp} and containing a |
3278 |
@c @code{%header_extension .hh} directive will produce a header file |
@c @code{%header-extension .hh} directive will produce a header file |
3279 |
@c named @file{foo.tab.hh} |
@c named @file{foo.tab.hh} |
3280 |
|
|
3281 |
@item %locations |
@item %locations |
3318 |
Request a pure (reentrant) parser program (@pxref{Pure Decl, ,A Pure |
Request a pure (reentrant) parser program (@pxref{Pure Decl, ,A Pure |
3319 |
(Reentrant) Parser}). |
(Reentrant) Parser}). |
3320 |
|
|
3321 |
@c @item %source_extension |
@c @item %source-extension |
3322 |
@c Specify the extension of the parser output file. |
@c Specify the extension of the parser output file. |
3323 |
@c |
@c |
3324 |
@c For example, a grammar file named @file{foo.yy} and containing a |
@c For example, a grammar file named @file{foo.yy} and containing a |
3325 |
@c @code{%source_extension .cpp} directive will produce a parser file |
@c @code{%source-extension .cpp} directive will produce a parser file |
3326 |
@c named @file{foo.tab.cpp} |
@c named @file{foo.tab.cpp} |
3327 |
|
|
3328 |
@item %token_table |
@item %token-table |
3329 |
Generate an array of token names in the parser file. The name of the |
Generate an array of token names in the parser file. The name of the |
3330 |
array is @code{yytname}; @code{yytname[@var{i}]} is the name of the |
array is @code{yytname}; @code{yytname[@var{i}]} is the name of the |
3331 |
token whose internal Bison token code number is @var{i}. The first three |
token whose internal Bison token code number is @var{i}. The first three |
3343 |
contains @samp{"*"*"}. (In C, that would be written as |
contains @samp{"*"*"}. (In C, that would be written as |
3344 |
@code{"\"*\"*\""}). |
@code{"\"*\"*\""}). |
3345 |
|
|
3346 |
When you specify @code{%token_table}, Bison also generates macro |
When you specify @code{%token-table}, Bison also generates macro |
3347 |
definitions for macros @code{YYNTOKENS}, @code{YYNNTS}, and |
definitions for macros @code{YYNTOKENS}, @code{YYNNTS}, and |
3348 |
@code{YYNRULES}, and @code{YYNSTATES}: |
@code{YYNRULES}, and @code{YYNSTATES}: |
3349 |
|
|
3374 |
output file is called @file{foo.output}.@refill |
output file is called @file{foo.output}.@refill |
3375 |
|
|
3376 |
@item %yacc |
@item %yacc |
|
@itemx %fixed-output-files |
|
3377 |
Pretend the option @option{--yacc} was given, i.e., imitate Yacc, |
Pretend the option @option{--yacc} was given, i.e., imitate Yacc, |
3378 |
including its naming conventions. @xref{Bison Options}, for more. |
including its naming conventions. @xref{Bison Options}, for more. |
3379 |
@end table |
@end table |
3564 |
@end smallexample |
@end smallexample |
3565 |
|
|
3566 |
The @code{yytname} table is generated only if you use the |
The @code{yytname} table is generated only if you use the |
3567 |
@code{%token_table} declaration. @xref{Decl Summary}. |
@code{%token-table} declaration. @xref{Decl Summary}. |
3568 |
@end itemize |
@end itemize |
3569 |
|
|
3570 |
@node Token Values |
@node Token Values |
3638 |
@node Pure Calling |
@node Pure Calling |
3639 |
@subsection Calling Conventions for Pure Parsers |
@subsection Calling Conventions for Pure Parsers |
3640 |
|
|
3641 |
When you use the Bison declaration @code{%pure_parser} to request a |
When you use the Bison declaration @code{%pure-parser} to request a |
3642 |
pure, reentrant parser, the global communication variables @code{yylval} |
pure, reentrant parser, the global communication variables @code{yylval} |
3643 |
and @code{yylloc} cannot be used. (@xref{Pure Decl, ,A Pure (Reentrant) |
and @code{yylloc} cannot be used. (@xref{Pure Decl, ,A Pure (Reentrant) |
3644 |
Parser}.) In such parsers the two global variables are replaced by |
Parser}.) In such parsers the two global variables are replaced by |
3738 |
the proper object type, or you can declare it as @code{void *} and |
the proper object type, or you can declare it as @code{void *} and |
3739 |
access the contents as shown above. |
access the contents as shown above. |
3740 |
|
|
3741 |
You can use @samp{%pure_parser} to request a reentrant parser without |
You can use @samp{%pure-parser} to request a reentrant parser without |
3742 |
also using @code{YYPARSE_PARAM}. Then you should call @code{yyparse} |
also using @code{YYPARSE_PARAM}. Then you should call @code{yyparse} |
3743 |
with no arguments, as usual. |
with no arguments, as usual. |
3744 |
|
|
5095 |
@need 1750 |
@need 1750 |
5096 |
@item -y |
@item -y |
5097 |
@itemx --yacc |
@itemx --yacc |
|
@itemx --fixed-output-files |
|
5098 |
Equivalent to @samp{-o y.tab.c}; the parser output file is called |
Equivalent to @samp{-o y.tab.c}; the parser output file is called |
5099 |
@file{y.tab.c}, and the other outputs are called @file{y.output} and |
@file{y.tab.c}, and the other outputs are called @file{y.output} and |
5100 |
@file{y.tab.h}. The purpose of this option is to imitate Yacc's output |
@file{y.tab.h}. The purpose of this option is to imitate Yacc's output |
5207 |
environment variable @code{BISON_SIMPLE} to the path of the file will |
environment variable @code{BISON_SIMPLE} to the path of the file will |
5208 |
cause Bison to use that copy instead. |
cause Bison to use that copy instead. |
5209 |
|
|
5210 |
When the @samp{%semantic_parser} declaration is used, Bison copies from |
When the @samp{%semantic-parser} declaration is used, Bison copies from |
5211 |
a file called @file{bison.hairy} instead. The location of this file can |
a file called @file{bison.hairy} instead. The location of this file can |
5212 |
also be specified or overridden in a similar fashion, with the |
also be specified or overridden in a similar fashion, with the |
5213 |
@code{BISON_HAIRY} environment variable. |
@code{BISON_HAIRY} environment variable. |
5227 |
\line{ --debug \leaderfill -t} |
\line{ --debug \leaderfill -t} |
5228 |
\line{ --defines \leaderfill -d} |
\line{ --defines \leaderfill -d} |
5229 |
\line{ --file-prefix \leaderfill -b} |
\line{ --file-prefix \leaderfill -b} |
|
\line{ --fixed-output-files \leaderfill -y} |
|
5230 |
\line{ --graph \leaderfill -g} |
\line{ --graph \leaderfill -g} |
5231 |
\line{ --help \leaderfill -h} |
\line{ --help \leaderfill -h} |
5232 |
\line{ --name-prefix \leaderfill -p} |
\line{ --name-prefix \leaderfill -p} |
5245 |
--debug -t |
--debug -t |
5246 |
--defines=@var{defines-file} -d |
--defines=@var{defines-file} -d |
5247 |
--file-prefix=@var{prefix} -b @var{file-prefix} |
--file-prefix=@var{prefix} -b @var{file-prefix} |
|
--fixed-output-files --yacc -y |
|
5248 |
--graph=@var{graph-file} -d |
--graph=@var{graph-file} -d |
5249 |
--help -h |
--help -h |
5250 |
--name-prefix=@var{prefix} -p @var{name-prefix} |
--name-prefix=@var{prefix} -p @var{name-prefix} |
5254 |
--token-table -k |
--token-table -k |
5255 |
--verbose -v |
--verbose -v |
5256 |
--version -V |
--version -V |
5257 |
|
--yacc -y |
5258 |
@end example |
@end example |
5259 |
@end ifinfo |
@end ifinfo |
5260 |
|
|
5430 |
Bison declaration to set tge prefix of the output files. @xref{Decl |
Bison declaration to set tge prefix of the output files. @xref{Decl |
5431 |
Summary}. |
Summary}. |
5432 |
|
|
5433 |
@c @item %source_extension |
@c @item %source-extension |
5434 |
@c Bison declaration to specify the generated parser output file extension. |
@c Bison declaration to specify the generated parser output file extension. |
5435 |
@c @xref{Decl Summary}. |
@c @xref{Decl Summary}. |
5436 |
@c |
@c |
5437 |
@c @item %header_extension |
@c @item %header-extension |
5438 |
@c Bison declaration to specify the generated parser header file extension |
@c Bison declaration to specify the generated parser header file extension |
5439 |
@c if required. @xref{Decl Summary}. |
@c if required. @xref{Decl Summary}. |
5440 |
|
|