X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/a73aa764a1d4b4cdf352558f030bcfcccfe97d7f..5202b6ac1d3662fe283240aab1b29f35607995cd:/doc/bison.texi diff --git a/doc/bison.texi b/doc/bison.texi index c1cafee7..aad2b8c3 100644 --- a/doc/bison.texi +++ b/doc/bison.texi @@ -33,7 +33,7 @@ This manual (@value{UPDATED}) is for GNU Bison (version @value{VERSION}), the GNU parser generator. -Copyright @copyright{} 1988-1993, 1995, 1998-2012 Free Software +Copyright @copyright{} 1988-1993, 1995, 1998-2013 Free Software Foundation, Inc. @quotation @@ -186,7 +186,6 @@ Bison Grammar Files * Grammar Outline:: Overall layout of the grammar file. * Symbols:: Terminal and nonterminal symbols. * Rules:: How to write grammar rules. -* Recursion:: Writing recursive rules. * Semantics:: Semantic values and actions. * Tracking Locations:: Locations and actions. * Named References:: Using named references in actions. @@ -201,6 +200,13 @@ Outline of a Bison Grammar * Grammar Rules:: Syntax and usage of the grammar rules section. * Epilogue:: Syntax and usage of the epilogue. +Grammar Rules + +* Rules Syntax:: Syntax of the rules. +* Empty Rules:: Symbols that can match the empty string. +* Recursion:: Writing recursive rules. + + Defining Language Semantics * Value Type:: Specifying one data type for all semantic values. @@ -1007,7 +1013,7 @@ Let's consider an example, vastly simplified from a C++ grammar. %% prog: - /* Nothing. */ + %empty | prog stmt @{ printf ("\n"); @} ; @@ -1538,6 +1544,7 @@ calculator. As in C, comments are placed between @samp{/*@dots{}*/}. @example /* Reverse polish notation calculator. */ +@group %@{ #define YYSTYPE double #include @@ -1545,6 +1552,7 @@ calculator. As in C, comments are placed between @samp{/*@dots{}*/}. int yylex (void); void yyerror (char const *); %@} +@end group %token NUM @@ -1589,7 +1597,7 @@ Here are the grammar rules for the reverse polish notation calculator. @example @group input: - /* empty */ + %empty | input line ; @end group @@ -1646,7 +1654,7 @@ Consider the definition of @code{input}: @example input: - /* empty */ + %empty | input line ; @end example @@ -1661,8 +1669,9 @@ The first alternative is empty because there are no symbols between the colon and the first @samp{|}; this means that @code{input} can match an empty string of input (no tokens). We write the rules this way because it is legitimate to type @kbd{Ctrl-d} right after you start the calculator. -It's conventional to put an empty alternative first and write the comment -@samp{/* empty */} in it. +It's conventional to put an empty alternative first and to use the +(optional) @code{%empty} directive, or to write the comment @samp{/* empty +*/} in it (@pxref{Empty Rules}). The second alternate rule (@code{input line}) handles all nontrivial input. It means, ``After reading any number of lines, read one more line if @@ -2002,7 +2011,7 @@ parentheses nested to arbitrary depth. Here is the Bison code for %% /* The grammar follows. */ @group input: - /* empty */ + %empty | input line ; @end group @@ -2182,7 +2191,7 @@ wrong expressions or subexpressions. @example @group input: - /* empty */ + %empty | input line ; @end group @@ -2394,7 +2403,7 @@ Here are the C and Bison declarations for the multi-function calculator. %@{ #include /* For printf, etc. */ #include /* For pow, used in the grammar. */ - #include "calc.h" /* Contains definition of `symrec'. */ + #include "calc.h" /* Contains definition of 'symrec'. */ int yylex (void); void yyerror (char const *); %@} @@ -2411,7 +2420,7 @@ Here are the C and Bison declarations for the multi-function calculator. %type exp @group -%right '=' +%precedence '=' %left '-' '+' %left '*' '/' %precedence NEG /* negation--unary minus */ @@ -2453,7 +2462,7 @@ those which mention @code{VAR} or @code{FNCT}, are new. %% /* The grammar follows. */ @group input: - /* empty */ + %empty | input line ; @end group @@ -2523,7 +2532,7 @@ struct symrec @group typedef struct symrec symrec; -/* The symbol table: a chain of `struct symrec'. */ +/* The symbol table: a chain of 'struct symrec'. */ extern symrec *sym_table; symrec *putsym (char const *, int); @@ -2558,7 +2567,7 @@ struct init const arith_fncts[] = @end group @group -/* The symbol table: a chain of `struct symrec'. */ +/* The symbol table: a chain of 'struct symrec'. */ symrec *sym_table; @end group @@ -2787,7 +2796,6 @@ The Bison grammar file conventionally has a name ending in @samp{.y}. * Grammar Outline:: Overall layout of the grammar file. * Symbols:: Terminal and nonterminal symbols. * Rules:: How to write grammar rules. -* Recursion:: Writing recursive rules. * Semantics:: Semantic values and actions. * Tracking Locations:: Locations and actions. * Named References:: Using named references in actions. @@ -2857,21 +2865,27 @@ can be done with two @var{Prologue} blocks, one before and one after the @code{%union} declaration. @example +@group %@{ #define _GNU_SOURCE #include #include "ptypes.h" %@} +@end group +@group %union @{ long int n; tree t; /* @r{@code{tree} is defined in @file{ptypes.h}.} */ @} +@end group +@group %@{ static void print_token_value (FILE *, int, YYSTYPE); #define YYPRINT(F, N, L) print_token_value (F, N, L) %@} +@end group @dots{} @end example @@ -2903,21 +2917,27 @@ location, or it can be one of @code{requires}, @code{provides}, Look again at the example of the previous section: @example +@group %@{ #define _GNU_SOURCE #include #include "ptypes.h" %@} +@end group +@group %union @{ long int n; tree t; /* @r{@code{tree} is defined in @file{ptypes.h}.} */ @} +@end group +@group %@{ static void print_token_value (FILE *, int, YYSTYPE); #define YYPRINT(F, N, L) print_token_value (F, N, L) %@} +@end group @dots{} @end example @@ -2955,7 +2975,7 @@ Let's go ahead and add the new @code{YYLTYPE} definition and the #include /* WARNING: The following code really belongs - * in a `%code requires'; see below. */ + * in a '%code requires'; see below. */ #include "ptypes.h" #define YYLTYPE YYLTYPE @@ -2969,16 +2989,20 @@ Let's go ahead and add the new @code{YYLTYPE} definition and the @} YYLTYPE; @} +@group %union @{ long int n; tree t; /* @r{@code{tree} is defined in @file{ptypes.h}.} */ @} +@end group +@group %code @{ static void print_token_value (FILE *, int, YYSTYPE); #define YYPRINT(F, N, L) print_token_value (F, N, L) static void trace_token (enum yytokentype token, YYLTYPE loc); @} +@end group @dots{} @end example @@ -3389,7 +3413,18 @@ value of the error token is 256, unless you explicitly assigned 256 to one of your tokens with a @code{%token} declaration. @node Rules -@section Syntax of Grammar Rules +@section Grammar Rules + +A Bison grammar is a list of rules. + +@menu +* Rules Syntax:: Syntax of the rules. +* Empty Rules:: Symbols that can match the empty string. +* Recursion:: Writing recursive rules. +@end menu + +@node Rules Syntax +@subsection Syntax of Grammar Rules @cindex rule syntax @cindex grammar rule syntax @cindex syntax of grammar rules @@ -3463,33 +3498,57 @@ be joined with the vertical-bar character @samp{|} as follows: @noindent They are still considered distinct rules even when joined in this way. -If @var{components} in a rule is empty, it means that @var{result} can -match the empty string. For example, here is how to define a -comma-separated sequence of zero or more @code{exp} groupings: +@node Empty Rules +@subsection Empty Rules +@cindex empty rule +@cindex rule, empty +@findex %empty + +A rule is said to be @dfn{empty} if its right-hand side (@var{components}) +is empty. It means that @var{result} can match the empty string. For +example, here is how to define an optional semicolon: + +@example +semicolon.opt: | ";"; +@end example + +@noindent +It is easy not to see an empty rule, especially when @code{|} is used. The +@code{%empty} directive allows to make explicit that a rule is empty on +purpose: @example @group -expseq: - /* empty */ -| expseq1 +semicolon.opt: + %empty +| ";" ; @end group +@end example + +Flagging a non-empty rule with @code{%empty} is an error. If run with +@option{-Wempty-rule}, @command{bison} will report empty rules without +@code{%empty}. Using @code{%empty} enables this warning, unless +@option{-Wno-empty-rule} was specified. +The @code{%empty} directive is a Bison extension, it does not work with +Yacc. To remain compatible with POSIX Yacc, it is customary to write a +comment @samp{/* empty */} in each rule with no components: + +@example @group -expseq1: - exp -| expseq1 ',' exp +semicolon.opt: + /* empty */ +| ";" ; @end group @end example -@noindent -It is customary to write a comment @samp{/* empty */} in each rule -with no components. @node Recursion -@section Recursive Rules +@subsection Recursive Rules @cindex recursive rule +@cindex rule, recursive A rule is called @dfn{recursive} when its @var{result} nonterminal appears also on its right hand side. Nearly all Bison grammars need to @@ -3739,7 +3798,7 @@ foo: @group bar: - /* empty */ @{ previous_expr = $0; @} + %empty @{ previous_expr = $0; @} ; @end group @end example @@ -3916,16 +3975,20 @@ declare a destructor for that symbol: @group %type let %destructor @{ pop_context ($$); @} let +@end group %% +@group stmt: let stmt @{ $$ = $2; pop_context ($let); @}; +@end group +@group let: "let" '(' var ')' @{ @@ -3960,9 +4023,9 @@ exp: @{ a(); @} "b" @{ c(); @} @{ d(); @} "e" @{ f(); @}; is translated into: @example -$@@1: /* empty */ @{ a(); @}; -$@@2: /* empty */ @{ c(); @}; -$@@3: /* empty */ @{ d(); @}; +$@@1: %empty @{ a(); @}; +$@@2: %empty @{ c(); @}; +$@@3: %empty @{ d(); @}; exp: $@@1 "b" $@@2 $@@3 "e" @{ f(); @}; @end example @@ -3981,9 +4044,9 @@ exp: @{ a(); @} "b" @{ $$ = c(); @} @{ d(); @} "e" @{ f = $1; @}; is translated into @example -@@1: /* empty */ @{ a(); @}; -@@2: /* empty */ @{ $$ = c(); @}; -$@@3: /* empty */ @{ d(); @}; +@@1: %empty @{ a(); @}; +@@2: %empty @{ $$ = c(); @}; +$@@3: %empty @{ d(); @}; exp: @@1 "b" @@2 $@@3 "e" @{ f = $1; @} @end example @@ -4092,7 +4155,7 @@ serves as a subroutine: @example @group subroutine: - /* empty */ @{ prepare_for_local_variables (); @} + %empty @{ prepare_for_local_variables (); @} ; @end group @@ -5333,7 +5396,7 @@ For instance with @samp{%define api.prefix "calc"} and @samp{%defines @end deffn @deffn {Directive} %defines @var{defines-file} -Same as above, but save in the file @var{defines-file}. +Same as above, but save in the file @file{@var{defines-file}}. @end deffn @deffn {Directive} %destructor @@ -5396,7 +5459,7 @@ own right. @end deffn @deffn {Directive} %output "@var{file}" -Specify @var{file} for the parser implementation file. +Generate the parser implementation in @file{@var{file}}. @end deffn @deffn {Directive} %pure-parser @@ -5521,12 +5584,9 @@ values, depend on the selected target language and/or the parser skeleton (@pxref{Decl Summary,,%language}, @pxref{Decl Summary,,%skeleton}). Unaccepted @var{variable}s produce an error. -Some of the accepted @var{variable}s are: +Some of the accepted @var{variable}s are described below. -@table @code -@c ================================================== api.namespace -@item api.namespace -@findex %define api.namespace +@deffn Directive {%define api.namespace} "@var{namespace}" @itemize @item Languages(s): C++ @@ -5574,11 +5634,11 @@ lexical analyzer function. For example, if you specify: The parser namespace is @code{foo} and @code{yylex} is referenced as @code{bar::lex}. @end itemize -@c namespace +@end deffn +@c api.namespace @c ================================================== api.location.type -@item @code{api.location.type} -@findex %define api.location.type +@deffn {Directive} {%define api.location.type} @var{type} @itemize @bullet @item Language(s): C++, Java @@ -5590,12 +5650,14 @@ The parser namespace is @code{foo} and @code{yylex} is referenced as @item Default Value: none -@item History: introduced in Bison 2.7 +@item History: +Introduced in Bison 2.7 for C, C++ and Java. Introduced under the name +@code{location_type} for C++ in Bison 2.5 and for Java in Bison 2.4. @end itemize +@end deffn @c ================================================== api.prefix -@item api.prefix -@findex %define api.prefix +@deffn {Directive} {%define api.prefix} @var{prefix} @itemize @bullet @item Language(s): All @@ -5609,10 +5671,10 @@ The parser namespace is @code{foo} and @code{yylex} is referenced as @item History: introduced in Bison 2.6 @end itemize +@end deffn @c ================================================== api.pure -@item api.pure -@findex %define api.pure +@deffn Directive {%define api.pure} @itemize @bullet @item Language(s): C @@ -5654,15 +5716,16 @@ Reporting Function @code{yyerror}}) @item Default Value: @code{false} -@item History: the @code{full} value was introduced in Bison 2.7 +@item History: +the @code{full} value was introduced in Bison 2.7 @end itemize +@end deffn @c api.pure @c ================================================== api.push-pull -@item api.push-pull -@findex %define api.push-pull +@deffn Directive {%define api.push-pull} @var{kind} @itemize @bullet @item Language(s): C (deterministic parsers only) @@ -5676,13 +5739,13 @@ More user feedback will help to stabilize it.) @item Default Value: @code{pull} @end itemize +@end deffn @c api.push-pull @c ================================================== api.token.constructor -@item api.token.constructor -@findex %define api.token.constructor +@deffn Directive {%define api.token.constructor} @itemize @bullet @item Language(s): @@ -5701,12 +5764,12 @@ Boolean. @item History: introduced in Bison 2.8 @end itemize +@end deffn @c api.token.constructor @c ================================================== api.token.prefix -@item api.token.prefix -@findex %define api.token.prefix +@deffn Directive {%define api.token.prefix} @var{prefix} @itemize @item Languages(s): all @@ -5741,13 +5804,39 @@ empty @item History: introduced in Bison 2.8 @end itemize +@end deffn @c api.token.prefix +@c ================================================== api.value.type +@deffn Directive {%define api.value.type} @var{type} +@itemize @bullet +@item Language(s): +C++ + +@item Purpose: +Request variant-based semantic values. +@xref{C++ Variants}. + +@item Default Value: +FIXME: +@item History: +introduced in Bison 2.8. Was introduced for Java only in 2.3b as +@code{stype}. +@end itemize +@end deffn +@c api.value.type + + +@c ================================================== location_type +@deffn Directive {%define location_type} +Obsoleted by @code{api.location.type} since Bison 2.7. +@end deffn + + @c ================================================== lr.default-reduction -@item lr.default-reduction -@findex %define lr.default-reduction +@deffn Directive {%define lr.default-reduction} @var{when} @itemize @bullet @item Language(s): all @@ -5767,11 +5856,11 @@ feedback will help to stabilize it.) introduced as @code{lr.default-reduction} in 2.5, renamed as @code{lr.default-reduction} in 2.8. @end itemize +@end deffn @c ============================================ lr.keep-unreachable-state -@item lr.keep-unreachable-state -@findex %define lr.keep-unreachable-state +@deffn Directive {%define lr.keep-unreachable-state} @itemize @bullet @item Language(s): all @@ -5779,16 +5868,17 @@ introduced as @code{lr.default-reduction} in 2.5, renamed as remain in the parser tables. @xref{Unreachable States}. @item Accepted Values: Boolean @item Default Value: @code{false} -@end itemize +@item History: introduced as @code{lr.keep_unreachable_states} in 2.3b, renamed as @code{lr.keep-unreachable-states} in 2.5, and as @code{lr.keep-unreachable-state} in 2.8. +@end itemize +@end deffn @c lr.keep-unreachable-state @c ================================================== lr.type -@item lr.type -@findex %define lr.type +@deffn Directive {%define lr.type} @var{type} @itemize @bullet @item Language(s): all @@ -5801,18 +5891,16 @@ More user feedback will help to stabilize it.) @item Default Value: @code{lalr} @end itemize - +@end deffn @c ================================================== namespace -@item namespace -@findex %define namespace +@deffn Directive %define namespace @var{namespace} Obsoleted by @code{api.namespace} @c namespace - +@end deffn @c ================================================== parse.assert -@item parse.assert -@findex %define parse.assert +@deffn Directive {%define parse.assert} @itemize @item Languages(s): C++ @@ -5826,12 +5914,12 @@ destroyed properly. This option checks these constraints. @item Default Value: @code{false} @end itemize +@end deffn @c parse.assert @c ================================================== parse.error -@item parse.error -@findex %define parse.error +@deffn Directive {%define parse.error} @itemize @item Languages(s): all @@ -5853,12 +5941,12 @@ However, this report can often be incorrect when LAC is not enabled @item Default Value: @code{simple} @end itemize +@end deffn @c parse.error @c ================================================== parse.lac -@item parse.lac -@findex %define parse.lac +@deffn Directive {%define parse.lac} @itemize @item Languages(s): C (deterministic parsers only) @@ -5868,11 +5956,11 @@ syntax error handling. @xref{LAC}. @item Accepted Values: @code{none}, @code{full} @item Default Value: @code{none} @end itemize +@end deffn @c parse.lac @c ================================================== parse.trace -@item parse.trace -@findex %define parse.trace +@deffn Directive {%define parse.trace} @itemize @item Languages(s): C, C++, Java @@ -5890,30 +5978,9 @@ compiled. @item Default Value: @code{false} @end itemize +@end deffn @c parse.trace -@c ================================================== variant -@item variant -@findex %define variant - -@itemize @bullet -@item Language(s): -C++ - -@item Purpose: -Request variant-based semantic values. -@xref{C++ Variants}. - -@item Accepted Values: -Boolean. - -@item Default Value: -@code{false} -@end itemize -@c variant -@end table - - @node %code Summary @subsection %code Summary @findex %code @@ -6093,7 +6160,7 @@ parsers. To comply with this tradition, when @code{api.prefix} is used, @code{YYDEBUG} (not renamed) is used as a default value: @example -/* Enabling traces. */ +/* Debug traces. */ #ifndef CDEBUG # if defined YYDEBUG # if YYDEBUG @@ -6368,7 +6435,7 @@ yylex (void) return 0; @dots{} if (c == '+' || c == '-') - return c; /* Assume token type for `+' is '+'. */ + return c; /* Assume token type for '+' is '+'. */ @dots{} return INT; /* Return the type of the token. */ @dots{} @@ -7465,7 +7532,7 @@ of zero or more @code{word} groupings. @example @group sequence: - /* empty */ @{ printf ("empty sequence\n"); @} + %empty @{ printf ("empty sequence\n"); @} | maybeword | sequence word @{ printf ("added word %s\n", $2); @} ; @@ -7473,8 +7540,8 @@ sequence: @group maybeword: - /* empty */ @{ printf ("empty maybeword\n"); @} -| word @{ printf ("single word %s\n", $1); @} + %empty @{ printf ("empty maybeword\n"); @} +| word @{ printf ("single word %s\n", $1); @} ; @end group @end example @@ -7505,7 +7572,7 @@ proper way to define @code{sequence}: @example @group sequence: - /* empty */ @{ printf ("empty sequence\n"); @} + %empty @{ printf ("empty sequence\n"); @} | sequence word @{ printf ("added word %s\n", $2); @} ; @end group @@ -7516,7 +7583,7 @@ Here is another common error that yields a reduce/reduce conflict: @example @group sequence: - /* empty */ + %empty | sequence words | sequence redirects ; @@ -7524,14 +7591,14 @@ sequence: @group words: - /* empty */ + %empty | words word ; @end group @group redirects: - /* empty */ + %empty | redirects redirect ; @end group @@ -7554,7 +7621,7 @@ of sequence: @example sequence: - /* empty */ + %empty | sequence word | sequence redirect ; @@ -7566,7 +7633,7 @@ from being empty: @example @group sequence: - /* empty */ + %empty | sequence words | sequence redirects ; @@ -7610,7 +7677,7 @@ rule: %% @group sequence: - /* empty */ + %empty | sequence word %prec "sequence" | sequence redirect %prec "sequence" ; @@ -7632,7 +7699,7 @@ rule with the same precedence, but make them right-associative: %% @group sequence: - /* empty */ + %empty | sequence word %prec "word" | sequence redirect %prec "redirect" ; @@ -8329,7 +8396,7 @@ For example: @example stmts: - /* empty string */ + %empty | stmts '\n' | stmts exp '\n' | stmts error '\n' @@ -9631,7 +9698,7 @@ Here is a list of options that can be used with Bison, alphabetized by short option. It is followed by a cross key alphabetized by long option. -@c Please, keep this ordered as in `bison --help'. +@c Please, keep this ordered as in 'bison --help'. @noindent Operations modes: @table @option @@ -9712,6 +9779,72 @@ no effect on the conflict report. Deprecated constructs whose support will be removed in future versions of Bison. +@item empty-rule +Empty rules without @code{%empty}. @xref{Empty Rules}. Disabled by +default, but enabled by uses of @code{%empty}, unless +@option{-Wno-empty-rule} was specified. + +@item precedence +Useless precedence and associativity directives. Disabled by default. + +Consider for instance the following grammar: + +@example +@group +%nonassoc "=" +%left "+" +%left "*" +%precedence "(" +@end group +%% +@group +stmt: + exp +| "var" "=" exp +; +@end group + +@group +exp: + exp "+" exp +| exp "*" "num" +| "(" exp ")" +| "num" +; +@end group +@end example + +Bison reports: + +@c cannot leave the location and the [-Wprecedence] for lack of +@c width in PDF. +@example +@group +warning: useless precedence and associativity for "=" + %nonassoc "=" + ^^^ +@end group +@group +warning: useless associativity for "*", use %precedence + %left "*" + ^^^ +@end group +@group +warning: useless precedence for "(" + %precedence "(" + ^^^ +@end group +@end example + +One would get the exact same parser with the following directives instead: + +@example +@group +%left "+" +%precedence "*" +@end group +@end example + @item other All warnings not categorized above. These warnings are enabled by default. @@ -9720,9 +9853,11 @@ releases of Bison may move warnings from this category to new, more specific categories. @item all -All the warnings. +All the warnings except @code{yacc}. + @item none Turn off all the warnings. + @item error See @option{-Werror}, below. @end table @@ -9770,7 +9905,7 @@ an example, using the following file @file{in.y}: exp: exp '+' exp @{ $exp = $1 + $2; @}; @end example -When invoked with @option{-fcaret}, Bison will report: +When invoked with @option{-fcaret} (or nothing), Bison will report: @example @group @@ -9800,6 +9935,20 @@ in.y:3.32-33: error: $2 of 'exp' has no declared type @end group @end example +Whereas, when invoked with @option{-fno-caret}, Bison will only report: + +@example +@group +in.y:3.20-23: error: ambiguous reference: ‘$exp’ +in.y:3.1-3: refers to: $exp at $$ +in.y:3.6-8: refers to: $exp at $1 +in.y:3.14-16: refers to: $exp at $3 +in.y:3.32-33: error: $2 of ‘exp’ has no declared type +@end group +@end example + +This option is activated by default. + @end table @end table @@ -10115,10 +10264,9 @@ Symbols}. @node C++ Variants @subsubsection C++ Variants -Starting with version 2.6, Bison provides a @emph{variant} based -implementation of semantic values for C++. This alleviates all the -limitations reported in the previous section, and in particular, object -types can be used without pointers. +Bison provides a @emph{variant} based implementation of semantic values for +C++. This alleviates all the limitations reported in the previous section, +and in particular, object types can be used without pointers. To enable variant-based semantic values, set @code{%define} variable @code{variant} (@pxref{%define Summary,, variant}). Once this defined, @@ -10190,14 +10338,6 @@ therefore, since, as far as we know, @code{double} is the most demanding type on all platforms, alignments are enforced for @code{double} whatever types are actually used. This may waste space in some cases. -@item -Our implementation is not conforming with strict aliasing rules. Alias -analysis is a technique used in optimizing compilers to detect when two -pointers are disjoint (they cannot ``meet''). Our implementation breaks -some of the rules that G++ 4.4 uses in its alias analysis, so @emph{strict -alias analysis must be disabled}. Use the option -@option{-fno-strict-aliasing} to compile the generated parser. - @item There might be portability issues we are not aware of. @end itemize @@ -10546,7 +10686,7 @@ or @node Complete Symbols @subsubsection Complete Symbols -If you specified both @code{%define variant} and +If you specified both @code{%define api.value.type variant} and @code{%define api.token.constructor}, the @code{parser} class also defines the class @code{parser::symbol_type} which defines a @emph{complete} symbol, aggregating its type (i.e., the @@ -10810,7 +10950,7 @@ the grammar for. @noindent @findex %define api.token.constructor -@findex %define variant +@findex %define api.value.type variant This example will use genuine C++ objects as semantic values, therefore, we require the variant-based interface. To make sure we properly use it, we enable assertions. To fully benefit from type-safety and more natural @@ -10819,8 +10959,8 @@ definition of ``symbol'', we enable @code{api.token.constructor}. @comment file: calc++-parser.yy @example %define api.token.constructor +%define api.value.type variant %define parse.assert -%define variant @end example @noindent @@ -10950,7 +11090,7 @@ Location Tracking Calculator: @code{ltcalc}}). unit: assignments exp @{ driver.result = $2; @}; assignments: - /* Nothing. */ @{@} + %empty @{@} | assignments assignment @{@}; assignment: @@ -11019,7 +11159,7 @@ Finally, we enable scanner tracing. @comment file: calc++-scanner.ll @example -%option noyywrap nounput batch debug +%option noyywrap nounput batch debug noinput @end example @noindent @@ -11235,11 +11375,11 @@ semantic values' types (class names) should be specified in the By default, the semantic stack is declared to have @code{Object} members, which means that the class types you specify can be of any class. To improve the type safety of the parser, you can declare the common -superclass of all the semantic values using the @samp{%define stype} +superclass of all the semantic values using the @samp{%define api.value.type} directive. For example, after the following declaration: @example -%define stype "ASTNode" +%define api.value.type "ASTNode" @end example @noindent @@ -11465,7 +11605,7 @@ The return type can be changed using @code{%define api.position.type @deftypemethod {Lexer} {Object} getLVal () Return the semantic value of the last token that yylex returned. -The return type can be changed using @samp{%define stype +The return type can be changed using @samp{%define api.value.type "@var{class-name}".} @end deftypemethod @@ -11493,7 +11633,7 @@ Like @code{$@var{n}} but specifies a alternative type @var{typealt}. @defvar $$ The semantic value for the grouping made by the current rule. As a value, this is in the base type (@code{Object} or as specified by -@samp{%define stype}) as in not cast to the declared subtype because +@samp{%define api.value.type}) as in not cast to the declared subtype because casts are not allowed on the left-hand side of Java assignments. Use an explicit Java cast if the correct subtype is needed. @xref{Java Semantic Values}. @@ -11575,7 +11715,7 @@ corresponds to these C macros.}. @item Java lacks unions, so @code{%union} has no effect. Instead, semantic values have a common base type: @code{Object} or as specified by -@samp{%define stype}. Angle brackets on @code{%token}, @code{type}, +@samp{%define api.value.type}. Angle brackets on @code{%token}, @code{type}, @code{$@var{n}} and @code{$$} specify subtypes rather than fields of an union. The type of @code{$$}, even with angle brackets, is the base type since Java casts are not allow on the left-hand side of assignments. @@ -11751,7 +11891,7 @@ Whether the parser class is declared @code{public}. Default is false. @xref{Java Bison Interface}. @end deffn -@deffn {Directive} {%define stype} "@var{class}" +@deffn {Directive} {%define api.value.type} "@var{class}" The base type of semantic values. Default is @code{Object}. @xref{Java Semantic Values}. @end deffn @@ -12125,7 +12265,7 @@ operating system's name and version and your compiler's name and version. If you have trouble compiling, you should also include a transcript of the build session, starting with the invocation of `configure'. Depending on the nature of the bug, you may be asked to -send additional files as well (such as `config.h' or `config.cache'). +send additional files as well (such as @file{config.h} or @file{config.cache}). Patches are most welcome, but not required. That is, do not hesitate to send a bug report just because you cannot provide a fix. @@ -12340,6 +12480,11 @@ time to resolve reduce/reduce conflicts. @xref{GLR Parsers, ,Writing GLR Parsers}. @end deffn +@deffn {Directive} %empty +Bison declaration to declare make explicit that a rule has an empty +right-hand side. @xref{Empty Rules}. +@end deffn + @deffn {Symbol} $end The predefined token marking the end of the token stream. It cannot be used in the grammar. @@ -12606,13 +12751,6 @@ the next token. @xref{Lexical, ,The Lexical Analyzer Function @code{yylex}}. @end deffn -@deffn {Macro} YYLEX_PARAM -An obsolete macro for specifying an extra argument (or list of extra -arguments) for @code{yyparse} to pass to @code{yylex}. The use of this -macro is deprecated, and is supported only for Yacc like parsers. -@xref{Pure Calling,, Calling Conventions for Pure Parsers}. -@end deffn - @deffn {Variable} yylloc External variable in which @code{yylex} should place the line and column numbers associated with a token. (In a pure parser, it is a local