3168 |
@cindex declaration summary |
@cindex declaration summary |
3169 |
@cindex summary, Bison declaration |
@cindex summary, Bison declaration |
3170 |
|
|
3171 |
Here is a summary of all Bison declarations: |
Here is a summary of the declarations used to define a grammar: |
3172 |
|
|
3173 |
@table @code |
@table @code |
3174 |
@item %union |
@item %union |
3203 |
@item %expect |
@item %expect |
3204 |
Declare the expected number of shift-reduce conflicts |
Declare the expected number of shift-reduce conflicts |
3205 |
(@pxref{Expect Decl, ,Suppressing Conflict Warnings}). |
(@pxref{Expect Decl, ,Suppressing Conflict Warnings}). |
3206 |
|
@end table |
3207 |
|
|
3208 |
@item %yacc |
@sp 1 |
3209 |
@itemx %fixed_output_files |
@noindent |
3210 |
Pretend the option @option{--yacc} was given, i.e., imitate Yacc, |
In order to change the behavior of @command{bison}, use the following |
3211 |
including its naming conventions. @xref{Bison Options}, for more. |
directives: |
3212 |
|
|
3213 |
|
@table @code |
3214 |
|
@item %debug |
3215 |
|
Output a definition of the macro @code{YYDEBUG} into the parser file, so |
3216 |
|
that the debugging facilities are compiled. @xref{Debugging, ,Debugging |
3217 |
|
Your Parser}. |
3218 |
|
|
3219 |
|
@item %defines |
3220 |
|
Write an extra output file containing macro definitions for the token |
3221 |
|
type names defined in the grammar and the semantic value type |
3222 |
|
@code{YYSTYPE}, as well as a few @code{extern} variable declarations. |
3223 |
|
|
3224 |
|
If the parser output file is named @file{@var{name}.c} then this file |
3225 |
|
is named @file{@var{name}.h}.@refill |
3226 |
|
|
3227 |
|
This output file is essential if you wish to put the definition of |
3228 |
|
@code{yylex} in a separate source file, because @code{yylex} needs to |
3229 |
|
be able to refer to token type codes and the variable |
3230 |
|
@code{yylval}. @xref{Token Values, ,Semantic Values of Tokens}.@refill |
3231 |
|
|
3232 |
|
@item %file-prefix="@var{prefix}" |
3233 |
|
Specify a prefix to use for all Bison output file names. The names are |
3234 |
|
chosen as if the input file were named @file{@var{prefix}.y}. |
3235 |
|
|
3236 |
|
@c @item %header_extension |
3237 |
|
@c Specify the extension of the parser header file generated when |
3238 |
|
@c @code{%define} or @samp{-d} are used. |
3239 |
|
@c |
3240 |
|
@c For example, a grammar file named @file{foo.ypp} and containing a |
3241 |
|
@c @code{%header_extension .hh} directive will produce a header file |
3242 |
|
@c named @file{foo.tab.hh} |
3243 |
|
|
3244 |
@item %locations |
@item %locations |
3245 |
Generate the code processing the locations (@pxref{Action Features, |
Generate the code processing the locations (@pxref{Action Features, |
3248 |
grammar does not use it, using @samp{%locations} allows for more |
grammar does not use it, using @samp{%locations} allows for more |
3249 |
accurate parse error messages. |
accurate parse error messages. |
3250 |
|
|
3251 |
@item %pure_parser |
@item %name-prefix="@var{prefix}" |
3252 |
Request a pure (reentrant) parser program (@pxref{Pure Decl, ,A Pure |
Rename the external symbols used in the parser so that they start with |
3253 |
(Reentrant) Parser}). |
@var{prefix} instead of @samp{yy}. The precise list of symbols renamed |
3254 |
|
is @code{yyparse}, @code{yylex}, @code{yyerror}, @code{yynerrs}, |
3255 |
|
@code{yylval}, @code{yychar} and @code{yydebug}. For example, if you |
3256 |
|
use @samp{%name-prefix="c_"}, the names become @code{c_parse}, |
3257 |
|
@code{c_lex}, and so on. @xref{Multiple Parsers, ,Multiple Parsers in |
3258 |
|
the Same Program}. |
3259 |
|
|
3260 |
@item %no_parser |
@item %no-parser |
3261 |
Do not include any C code in the parser file; generate tables only. The |
Do not include any C code in the parser file; generate tables only. The |
3262 |
parser file contains just @code{#define} directives and static variable |
parser file contains just @code{#define} directives and static variable |
3263 |
declarations. |
declarations. |
3266 |
into a file named @file{@var{filename}.act}, in the form of a |
into a file named @file{@var{filename}.act}, in the form of a |
3267 |
brace-surrounded body fit for a @code{switch} statement. |
brace-surrounded body fit for a @code{switch} statement. |
3268 |
|
|
3269 |
@item %no_lines |
@item %no-lines |
3270 |
Don't generate any @code{#line} preprocessor commands in the parser |
Don't generate any @code{#line} preprocessor commands in the parser |
3271 |
file. Ordinarily Bison writes these commands in the parser file so that |
file. Ordinarily Bison writes these commands in the parser file so that |
3272 |
the C compiler and debuggers will associate errors and object code with |
the C compiler and debuggers will associate errors and object code with |
3274 |
associate errors with the parser file, treating it an independent source |
associate errors with the parser file, treating it an independent source |
3275 |
file in its own right. |
file in its own right. |
3276 |
|
|
3277 |
@item %debug |
@item %output="@var{filename}" |
3278 |
Output a definition of the macro @code{YYDEBUG} into the parser file, so |
Specify the @var{filename} for the parser file. |
|
that the debugging facilities are compiled. @xref{Debugging, ,Debugging |
|
|
Your Parser}. |
|
|
|
|
|
@item %defines |
|
|
Write an extra output file containing macro definitions for the token |
|
|
type names defined in the grammar and the semantic value type |
|
|
@code{YYSTYPE}, as well as a few @code{extern} variable declarations. |
|
|
|
|
|
If the parser output file is named @file{@var{name}.c} then this file |
|
|
is named @file{@var{name}.h}.@refill |
|
3279 |
|
|
3280 |
This output file is essential if you wish to put the definition of |
@item %pure-parser |
3281 |
@code{yylex} in a separate source file, because @code{yylex} needs to |
Request a pure (reentrant) parser program (@pxref{Pure Decl, ,A Pure |
3282 |
be able to refer to token type codes and the variable |
(Reentrant) Parser}). |
|
@code{yylval}. @xref{Token Values, ,Semantic Values of Tokens}.@refill |
|
3283 |
|
|
3284 |
@c @item %source_extension |
@c @item %source_extension |
3285 |
@c Specify the extension of the parser output file. |
@c Specify the extension of the parser output file. |
3287 |
@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 |
3288 |
@c @code{%source_extension .cpp} directive will produce a parser file |
@c @code{%source_extension .cpp} directive will produce a parser file |
3289 |
@c named @file{foo.tab.cpp} |
@c named @file{foo.tab.cpp} |
|
@c |
|
|
@c @item %header_extension |
|
|
@c Specify the extension of the parser header file generated when |
|
|
@c @code{%define} or @samp{-d} are used. |
|
|
@c |
|
|
@c For example, a garmmar file named @file{foo.ypp} and containing a |
|
|
@c @code{%header_extension .hh} directive will produce a header file |
|
|
@c named @file{foo.tab.hh} |
|
|
|
|
|
@item %verbose |
|
|
Write an extra output file containing verbose descriptions of the |
|
|
parser states and what is done for each type of look-ahead token in |
|
|
that state. |
|
|
|
|
|
This file also describes all the conflicts, both those resolved by |
|
|
operator precedence and the unresolved ones. |
|
|
|
|
|
The file's name is made by removing @samp{.tab.c} or @samp{.c} from |
|
|
the parser output file name, and adding @samp{.output} instead.@refill |
|
|
|
|
|
Therefore, if the input file is @file{foo.y}, then the parser file is |
|
|
called @file{foo.tab.c} by default. As a consequence, the verbose |
|
|
output file is called @file{foo.output}.@refill |
|
3290 |
|
|
3291 |
@item %token_table |
@item %token_table |
3292 |
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 |
3320 |
@item YYNSTATES |
@item YYNSTATES |
3321 |
The number of parser states (@pxref{Parser States}). |
The number of parser states (@pxref{Parser States}). |
3322 |
@end table |
@end table |
3323 |
|
|
3324 |
|
@item %verbose |
3325 |
|
Write an extra output file containing verbose descriptions of the |
3326 |
|
parser states and what is done for each type of look-ahead token in |
3327 |
|
that state. |
3328 |
|
|
3329 |
|
This file also describes all the conflicts, both those resolved by |
3330 |
|
operator precedence and the unresolved ones. |
3331 |
|
|
3332 |
|
The file's name is made by removing @samp{.tab.c} or @samp{.c} from |
3333 |
|
the parser output file name, and adding @samp{.output} instead.@refill |
3334 |
|
|
3335 |
|
Therefore, if the input file is @file{foo.y}, then the parser file is |
3336 |
|
called @file{foo.tab.c} by default. As a consequence, the verbose |
3337 |
|
output file is called @file{foo.output}.@refill |
3338 |
|
|
3339 |
|
@item %yacc |
3340 |
|
@itemx %fixed-output-files |
3341 |
|
Pretend the option @option{--yacc} was given, i.e., imitate Yacc, |
3342 |
|
including its naming conventions. @xref{Bison Options}, for more. |
3343 |
@end table |
@end table |
3344 |
|
|
3345 |
|
|
3346 |
|
|
3347 |
|
|
3348 |
@node Multiple Parsers |
@node Multiple Parsers |
3349 |
@section Multiple Parsers in the Same Program |
@section Multiple Parsers in the Same Program |
3350 |
|
|
5074 |
Your Parser}. |
Your Parser}. |
5075 |
|
|
5076 |
@item --locations |
@item --locations |
5077 |
Pretend that @code{%locactions} was specified. @xref{Decl Summary}. |
Pretend that @code{%locations} was specified. @xref{Decl Summary}. |
5078 |
|
|
5079 |
@item -p @var{prefix} |
@item -p @var{prefix} |
5080 |
@itemx --name-prefix=@var{prefix} |
@itemx --name-prefix=@var{prefix} |
5081 |
Rename the external symbols used in the parser so that they start with |
Pretend that @code{%name-prefix="@var{prefix}"} was specified. |
5082 |
@var{prefix} instead of @samp{yy}. The precise list of symbols renamed |
@xref{Decl Summary}. |
|
is @code{yyparse}, @code{yylex}, @code{yyerror}, @code{yynerrs}, |
|
|
@code{yylval}, @code{yychar} and @code{yydebug}. |
|
|
|
|
|
For example, if you use @samp{-p c}, the names become @code{cparse}, |
|
|
@code{clex}, and so on. |
|
|
|
|
|
@xref{Multiple Parsers, ,Multiple Parsers in the Same Program}. |
|
5083 |
|
|
5084 |
@item -l |
@item -l |
5085 |
@itemx --no-lines |
@itemx --no-lines |
5091 |
|
|
5092 |
@item -n |
@item -n |
5093 |
@itemx --no-parser |
@itemx --no-parser |
5094 |
Pretend that @code{%no_parser} was specified. @xref{Decl Summary}. |
Pretend that @code{%no-parser} was specified. @xref{Decl Summary}. |
5095 |
|
|
5096 |
@item -k |
@item -k |
5097 |
@itemx --token-table |
@itemx --token-table |
5098 |
Pretend that @code{%token_table} was specified. @xref{Decl Summary}. |
Pretend that @code{%token-table} was specified. @xref{Decl Summary}. |
5099 |
@end table |
@end table |
5100 |
|
|
5101 |
@noindent |
@noindent |
5103 |
|
|
5104 |
@table @option |
@table @option |
5105 |
@item -d |
@item -d |
5106 |
Pretend that @code{%verbose} was specified, i.e., write an extra output |
@itemx --defines |
5107 |
|
Pretend that @code{%defines} was specified, i.e., write an extra output |
5108 |
file containing macro definitions for the token type names defined in |
file containing macro definitions for the token type names defined in |
5109 |
the grammar and the semantic value type @code{YYSTYPE}, as well as a few |
the grammar and the semantic value type @code{YYSTYPE}, as well as a few |
5110 |
@code{extern} variable declarations. @xref{Decl Summary}. |
@code{extern} variable declarations. @xref{Decl Summary}. |
5111 |
|
|
5112 |
@item --defines=@var{defines-file} |
@item --defines=@var{defines-file} |
5113 |
The behaviour of @var{--defines} is the same than @samp{-d}. The only |
Same as above, but save in the file @var{defines-file}. |
|
difference is that it has an optionnal argument which is the name of |
|
|
the output filename. |
|
5114 |
|
|
5115 |
@item -b @var{file-prefix} |
@item -b @var{file-prefix} |
5116 |
@itemx --file-prefix=@var{prefix} |
@itemx --file-prefix=@var{prefix} |
5117 |
Specify a prefix to use for all Bison output file names. The names are |
Pretend that @code{%verbose} was specified, i.e, specify prefix to use |
5118 |
chosen as if the input file were named @file{@var{prefix}.c}. |
for all Bison output file names. @xref{Decl Summary}. |
5119 |
|
|
5120 |
@item -v |
@item -v |
5121 |
@itemx --verbose |
@itemx --verbose |
5122 |
Pretend that @code{%verbose} was specified, i.e, write an extra output |
Pretend that @code{%verbose} was specified, i.e, write an extra output |
5123 |
file containing verbose descriptions of the grammar and |
file containing verbose descriptions of the grammar and |
5124 |
parser. @xref{Decl Summary}, for more. |
parser. @xref{Decl Summary}. |
5125 |
|
|
5126 |
@item -o @var{outfile} |
@item -o @var{filename} |
5127 |
@itemx --output-file=@var{outfile} |
@itemx --output=@var{filename} |
5128 |
Specify the name @var{outfile} for the parser file. |
Specify the @var{filename} for the parser file. |
5129 |
|
|
5130 |
The other output files' names are constructed from @var{outfile} |
The other output files' names are constructed from @var{filename} as |
5131 |
as described under the @samp{-v} and @samp{-d} options. |
described under the @samp{-v} and @samp{-d} options. |
5132 |
|
|
5133 |
@item -g |
@item -g |
5134 |
Output a VCG definition of the LALR(1) grammar automaton computed by |
Output a VCG definition of the LALR(1) grammar automaton computed by |
5185 |
\line{ --name-prefix \leaderfill -p} |
\line{ --name-prefix \leaderfill -p} |
5186 |
\line{ --no-lines \leaderfill -l} |
\line{ --no-lines \leaderfill -l} |
5187 |
\line{ --no-parser \leaderfill -n} |
\line{ --no-parser \leaderfill -n} |
5188 |
\line{ --output-file \leaderfill -o} |
\line{ --output \leaderfill -o} |
5189 |
\line{ --token-table \leaderfill -k} |
\line{ --token-table \leaderfill -k} |
5190 |
\line{ --verbose \leaderfill -v} |
\line{ --verbose \leaderfill -v} |
5191 |
\line{ --version \leaderfill -V} |
\line{ --version \leaderfill -V} |
5204 |
--name-prefix=@var{prefix} -p @var{name-prefix} |
--name-prefix=@var{prefix} -p @var{name-prefix} |
5205 |
--no-lines -l |
--no-lines -l |
5206 |
--no-parser -n |
--no-parser -n |
5207 |
--output-file=@var{outfile} -o @var{outfile} |
--output=@var{outfile} -o @var{outfile} |
5208 |
--token-table -k |
--token-table -k |
5209 |
--verbose -v |
--verbose -v |
5210 |
--version -V |
--version -V |
5378 |
Bison declaration to create a header file meant for the scanner. |
Bison declaration to create a header file meant for the scanner. |
5379 |
@xref{Decl Summary}. |
@xref{Decl Summary}. |
5380 |
|
|
5381 |
|
@item %file-prefix="@var{prefix}" |
5382 |
|
Bison declaration to set tge prefix of the output files. @xref{Decl |
5383 |
|
Summary}. |
5384 |
|
|
5385 |
@c @item %source_extension |
@c @item %source_extension |
5386 |
@c Bison declaration to specify the generated parser output file extension. |
@c Bison declaration to specify the generated parser output file extension. |
5387 |
@c @xref{Decl Summary}. |
@c @xref{Decl Summary}. |
5394 |
Bison declaration to assign left associativity to token(s). |
Bison declaration to assign left associativity to token(s). |
5395 |
@xref{Precedence Decl, ,Operator Precedence}. |
@xref{Precedence Decl, ,Operator Precedence}. |
5396 |
|
|
5397 |
@item %no_lines |
@item %name-prefix="@var{prefix}" |
5398 |
|
Bison declaration to rename the external symbols. @xref{Decl Summary}. |
5399 |
|
|
5400 |
|
@item %no-lines |
5401 |
Bison declaration to avoid generating @code{#line} directives in the |
Bison declaration to avoid generating @code{#line} directives in the |
5402 |
parser file. @xref{Decl Summary}. |
parser file. @xref{Decl Summary}. |
5403 |
|
|
5405 |
Bison declaration to assign non-associativity to token(s). |
Bison declaration to assign non-associativity to token(s). |
5406 |
@xref{Precedence Decl, ,Operator Precedence}. |
@xref{Precedence Decl, ,Operator Precedence}. |
5407 |
|
|
5408 |
|
@item %output="@var{filename}" |
5409 |
|
Bison declaration to set the name of the parser file. @xref{Decl |
5410 |
|
Summary}. |
5411 |
|
|
5412 |
@item %prec |
@item %prec |
5413 |
Bison declaration to assign a precedence to a specific rule. |
Bison declaration to assign a precedence to a specific rule. |
5414 |
@xref{Contextual Precedence, ,Context-Dependent Precedence}. |
@xref{Contextual Precedence, ,Context-Dependent Precedence}. |
5415 |
|
|
5416 |
@item %pure_parser |
@item %pure-parser |
5417 |
Bison declaration to request a pure (reentrant) parser. |
Bison declaration to request a pure (reentrant) parser. |
5418 |
@xref{Pure Decl, ,A Pure (Reentrant) Parser}. |
@xref{Pure Decl, ,A Pure (Reentrant) Parser}. |
5419 |
|
|
5428 |
Bison declaration to declare token(s) without specifying precedence. |
Bison declaration to declare token(s) without specifying precedence. |
5429 |
@xref{Token Decl, ,Token Type Names}. |
@xref{Token Decl, ,Token Type Names}. |
5430 |
|
|
5431 |
@item %token_table |
@item %token-table |
5432 |
Bison declaration to include a token name table in the parser file. |
Bison declaration to include a token name table in the parser file. |
5433 |
@xref{Decl Summary}. |
@xref{Decl Summary}. |
5434 |
|
|