@@ -530,6 +530,8 @@ D Parsers
530
530
* D Parser Context Interface:: Circumstances of a syntax error
531
531
* D Scanner Interface:: Specifying the scanner for the parser
532
532
* D Action Features:: Special features for use in actions
533
+ * D Push Parser Interface:: Instantiating and running the push parser
534
+ * D Complete Symbols:: Using token constructors
533
535
534
536
Java Parsers
535
537
@@ -540,7 +542,7 @@ Java Parsers
540
542
* Java Parser Context Interface:: Circumstances of a syntax error
541
543
* Java Scanner Interface:: Specifying the scanner for the parser
542
544
* Java Action Features:: Special features for use in actions
543
- * Java Push Parser Interface:: Instantiating and running the a push parser
545
+ * Java Push Parser Interface:: Instantiating and running the push parser
544
546
* Java Differences:: Differences between C/C++ and Java Grammars
545
547
* Java Declarations Summary:: List of Bison declarations used with Java
546
548
@@ -5427,7 +5429,7 @@ Decl}).
5427
5429
@c This is the same text as for %destructor.
5428
5430
Invoke the braced @var{code} whenever the parser displays one of the
5429
5431
@var{symbols}. Within @var{code}, @code{yyo} denotes the output stream (a
5430
- @code{FILE*} in C, and an @code{std::ostream&} in C++), @code{$$} (or
5432
+ @code{FILE*} in C, an @code{std::ostream&} in C++, and @code{stdout} in D ), @code{$$} (or
5431
5433
@code{$<@var{tag}>$}) designates the semantic value associated with the
5432
5434
symbol, and @code{@@$} its location. The additional parser parameters are
5433
5435
also available (@pxref{Parser Function}).
@@ -6341,7 +6343,7 @@ Introduced in Bison 3.3 to replace @code{parser_class_name}.
6341
6343
@deffn {Directive} {%define api.prefix} @{@var{prefix}@}
6342
6344
6343
6345
@itemize @bullet
6344
- @item Language(s): All
6346
+ @item Language(s): C, C++, Java
6345
6347
6346
6348
@item Purpose: Rename exported symbols.
6347
6349
@xref{Multiple Parsers}.
@@ -6412,7 +6414,7 @@ the @code{full} value was introduced in Bison 2.7
6412
6414
@deffn Directive {%define api.push-pull} @var{kind}
6413
6415
6414
6416
@itemize @bullet
6415
- @item Language(s): C (deterministic parsers only), Java
6417
+ @item Language(s): C (deterministic parsers only), D, Java
6416
6418
6417
6419
@item Purpose: Request a pull parser, a push parser, or both.
6418
6420
@xref{Push Decl}.
@@ -6496,12 +6498,14 @@ introduced in Bison 3.6.
6496
6498
6497
6499
@itemize @bullet
6498
6500
@item Language(s):
6499
- C++
6501
+ C++, D
6500
6502
6501
6503
@item Purpose:
6502
- When variant-based semantic values are enabled (@pxref{C++ Variants}),
6503
- request that symbols be handled as a whole (type, value, and possibly
6504
- location) in the scanner. @xref{Complete Symbols}, for details.
6504
+ Request that symbols be handled as a whole (type, value, and possibly
6505
+ location) in the scanner. In the case of C++, it works only when
6506
+ variant-based semantic values are enabled
6507
+ (@pxref{C++ Variants}), @xref{Complete Symbols}, for details. In D,
6508
+ token constructor works with both "%union" and "%define api.value.type union".
6505
6509
6506
6510
@item Accepted Values:
6507
6511
Boolean.
@@ -6885,7 +6889,7 @@ However, this report can often be incorrect when LAC is not enabled
6885
6889
(@pxref{LAC}). Token name internationalization is supported.
6886
6890
6887
6891
@item @code{verbose}
6888
- Similar (but inferior) to @code{detailed}.
6892
+ Similar (but inferior) to @code{detailed}. The D parser does not support this value.
6889
6893
6890
6894
Error messages report the unexpected token, and possibly the expected ones.
6891
6895
However, this report can often be incorrect when LAC is not enabled
@@ -13795,6 +13799,8 @@ main (int argc, char *argv[])
13795
13799
* D Parser Context Interface:: Circumstances of a syntax error
13796
13800
* D Scanner Interface:: Specifying the scanner for the parser
13797
13801
* D Action Features:: Special features for use in actions
13802
+ * D Push Parser Interface:: Instantiating and running the push parser
13803
+ * D Complete Symbols:: Using token constructors
13798
13804
@end menu
13799
13805
13800
13806
@node D Bison Interface
@@ -13826,15 +13832,21 @@ No header file can be generated for D parsers. Do not use the
13826
13832
@node D Semantic Values
13827
13833
@subsection D Semantic Values
13828
13834
13829
- Semantic types are handled by %union, same as for C/C++ parsers.
13835
+ Semantic types are handled by "%union" and "%define api.value.type union",
13836
+ similat to C/C++ parsers. In the latter case, the union of the values is
13837
+ handled by the backend. In D, unions can hold classes, structs, etc., so
13838
+ this directive is more similar to "%define api.value.type variant" from C++.
13830
13839
13831
13840
D parsers do not support @code{%destructor}, since the language
13832
13841
adopts garbage collection. The parser will try to hold references
13833
13842
to semantic values for as little time as needed.
13834
13843
13835
- D parsers do not support @code{%printer}, as @code{toString()}
13836
- can be used to print the semantic values. This however may change
13837
- (in a backwards-compatible way) in future versions of Bison.
13844
+ D parsers support @code{%printer}. An example for the output of type @code{int},
13845
+ where @code{yyo} is the parser's debug output:
13846
+
13847
+ @example
13848
+ %printer @{ yyo.write($$); @} <int>
13849
+ @end example
13838
13850
13839
13851
13840
13852
@node D Location Values
@@ -13881,15 +13893,15 @@ The superclass and the implemented
13881
13893
interfaces of the parser class can be specified with the @code{%define
13882
13894
api.parser.extends} and @samp{%define api.parser.implements} directives.
13883
13895
13884
- The parser class defines a inner
13885
- interface, @code{Lexer} (see @ref{D Scanner Interface}). Other than
13886
- these inner class/ interface, and the members described in the interface
13896
+ The parser class defines an interface,
13897
+ @code{Lexer} (see @ref{D Scanner Interface}). Other than
13898
+ this interface and the members described in the interface
13887
13899
below, all the other members and fields are preceded with a @code{yy} or
13888
13900
@code{YY} prefix to avoid clashes with user code.
13889
13901
13890
13902
The parser class can be extended using the @code{%parse-param}
13891
13903
directive. Each occurrence of the directive will add a by default public field to the parser class, and an argument to its constructor,
13892
- which initialize them automatically.
13904
+ which initializes them automatically.
13893
13905
13894
13906
@deftypeop {Constructor} {YYParser} {} this(@var{lex_param}, @dots{}, @var{parse_param}, @dots{})
13895
13907
Build a new parser object with embedded @code{%code lexer}. There are
@@ -14012,7 +14024,7 @@ invoke @samp{%define parse.error custom}.
14012
14024
14013
14025
@defcv {Type} {YYParser} {SymbolKind}
14014
14026
A struct containing an enum of all the grammar symbols, tokens and nonterminals. Its
14015
- enumerators are forged from the symbol names. Use void toString(W)(W sink) to get
14027
+ enumerators are forged from the symbol names. Use @code{ void toString(W)(W sink)} to get
14016
14028
the symbol names.
14017
14029
@end defcv
14018
14030
@@ -14135,6 +14147,61 @@ errors. This is useful primarily in error rules.
14135
14147
@xref{Error Recovery}.
14136
14148
@end deffn
14137
14149
14150
+ @node D Push Parser Interface
14151
+ @subsection D Push Parser Interface
14152
+ @c - define push_parse
14153
+ @findex %define api.push-pull
14154
+
14155
+ Normally, Bison generates a pull parser for D.
14156
+ The following Bison declaration says that you want the parser to be a push
14157
+ parser (@pxref{%define Summary}):
14158
+
14159
+ @example
14160
+ %define api.push-pull push
14161
+ @end example
14162
+
14163
+ Most of the discussion about the D pull Parser Interface, (@pxref{D
14164
+ Parser Interface}) applies to the push parser interface as well.
14165
+
14166
+ When generating a push parser, the method @code{pushParse} is created with
14167
+ the following signature:
14168
+
14169
+ @deftypemethod {YYParser} {int} pushParse (@code{Symbol} @var{sym})
14170
+ @end deftypemethod
14171
+
14172
+ The primary difference with respect to a pull parser is that the parser
14173
+ method @code{pushParse} is invoked repeatedly to parse each token. This
14174
+ function is available if either the "%define api.push-pull push" or "%define
14175
+ api.push-pull both" declaration is used (@pxref{%define
14176
+ Summary}).
14177
+
14178
+ The value returned by the @code{pushParse} method is one of the following:
14179
+ @code{ACCEPT}, @code{ABORT}, or @code{PUSH_MORE}. This
14180
+ new value, @code{PUSH_MORE}, may be returned if more input is required to
14181
+ finish parsing the grammar.
14182
+
14183
+ If api.push-pull is declared as @code{both}, then the generated parser class
14184
+ will also implement the @code{parse} method. This method's body is a loop
14185
+ that repeatedly invokes the scanner and then passes the values obtained from
14186
+ the scanner to the @code{pushParse} method.
14187
+
14188
+ @node D Complete Symbols
14189
+ @subsection D Complete Symbols
14190
+
14191
+ The user can return from yylex() by calling the Symbol method of the
14192
+ same name as the TokenKind reported, and adding the parameters for
14193
+ value and location if necessary. These methods generate compile-time
14194
+ errors if the parameters are not correlated. Token constructors work
14195
+ with both "%union" and "%define api.value.type union".
14196
+
14197
+ The order of the parameters is the same as for the Symbol constructor.
14198
+ An example for the TokenKind @code{NUM}, which has value @code{ival} and with
14199
+ location tracking activated:
14200
+
14201
+ @example
14202
+ Symbol.NUM(ival, location);
14203
+ @end example
14204
+
14138
14205
@node Java Parsers
14139
14206
@section Java Parsers
14140
14207
@@ -14146,7 +14213,7 @@ errors. This is useful primarily in error rules.
14146
14213
* Java Parser Context Interface:: Circumstances of a syntax error
14147
14214
* Java Scanner Interface:: Specifying the scanner for the parser
14148
14215
* Java Action Features:: Special features for use in actions
14149
- * Java Push Parser Interface:: Instantiating and running the a push parser
14216
+ * Java Push Parser Interface:: Instantiating and running the push parser
14150
14217
* Java Differences:: Differences between C/C++ and Java Grammars
14151
14218
* Java Declarations Summary:: List of Bison declarations used with Java
14152
14219
@end menu
@@ -14313,7 +14380,7 @@ below, all the other members and fields are preceded with a @code{yy} or
14313
14380
The parser class can be extended using the @code{%parse-param}
14314
14381
directive. Each occurrence of the directive will add a @code{protected
14315
14382
final} field to the parser class, and an argument to its constructor,
14316
- which initialize them automatically.
14383
+ which initializes them automatically.
14317
14384
14318
14385
@deftypeop {Constructor} {YYParser} {} YYParser (@var{lex_param}, @dots{}, @var{parse_param}, @dots{})
14319
14386
Build a new parser object with embedded @code{%code lexer}. There are
0 commit comments