Skip to content

Commit 7eee2cc

Browse files
adelavaisakimd
authored andcommitted
d: update documentation
* doc/bison.texi: Various fixes. (D Push Parser Interface, D Complete Symbols): New sections.
1 parent f993147 commit 7eee2cc

File tree

1 file changed

+87
-20
lines changed

1 file changed

+87
-20
lines changed

doc/bison.texi

Lines changed: 87 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,8 @@ D Parsers
530530
* D Parser Context Interface:: Circumstances of a syntax error
531531
* D Scanner Interface:: Specifying the scanner for the parser
532532
* 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
533535

534536
Java Parsers
535537

@@ -540,7 +542,7 @@ Java Parsers
540542
* Java Parser Context Interface:: Circumstances of a syntax error
541543
* Java Scanner Interface:: Specifying the scanner for the parser
542544
* 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
544546
* Java Differences:: Differences between C/C++ and Java Grammars
545547
* Java Declarations Summary:: List of Bison declarations used with Java
546548

@@ -5427,7 +5429,7 @@ Decl}).
54275429
@c This is the same text as for %destructor.
54285430
Invoke the braced @var{code} whenever the parser displays one of the
54295431
@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
54315433
@code{$<@var{tag}>$}) designates the semantic value associated with the
54325434
symbol, and @code{@@$} its location. The additional parser parameters are
54335435
also available (@pxref{Parser Function}).
@@ -6341,7 +6343,7 @@ Introduced in Bison 3.3 to replace @code{parser_class_name}.
63416343
@deffn {Directive} {%define api.prefix} @{@var{prefix}@}
63426344

63436345
@itemize @bullet
6344-
@item Language(s): All
6346+
@item Language(s): C, C++, Java
63456347

63466348
@item Purpose: Rename exported symbols.
63476349
@xref{Multiple Parsers}.
@@ -6412,7 +6414,7 @@ the @code{full} value was introduced in Bison 2.7
64126414
@deffn Directive {%define api.push-pull} @var{kind}
64136415

64146416
@itemize @bullet
6415-
@item Language(s): C (deterministic parsers only), Java
6417+
@item Language(s): C (deterministic parsers only), D, Java
64166418

64176419
@item Purpose: Request a pull parser, a push parser, or both.
64186420
@xref{Push Decl}.
@@ -6496,12 +6498,14 @@ introduced in Bison 3.6.
64966498

64976499
@itemize @bullet
64986500
@item Language(s):
6499-
C++
6501+
C++, D
65006502

65016503
@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".
65056509

65066510
@item Accepted Values:
65076511
Boolean.
@@ -6885,7 +6889,7 @@ However, this report can often be incorrect when LAC is not enabled
68856889
(@pxref{LAC}). Token name internationalization is supported.
68866890

68876891
@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.
68896893

68906894
Error messages report the unexpected token, and possibly the expected ones.
68916895
However, this report can often be incorrect when LAC is not enabled
@@ -13795,6 +13799,8 @@ main (int argc, char *argv[])
1379513799
* D Parser Context Interface:: Circumstances of a syntax error
1379613800
* D Scanner Interface:: Specifying the scanner for the parser
1379713801
* 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
1379813804
@end menu
1379913805

1380013806
@node D Bison Interface
@@ -13826,15 +13832,21 @@ No header file can be generated for D parsers. Do not use the
1382613832
@node D Semantic Values
1382713833
@subsection D Semantic Values
1382813834

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++.
1383013839

1383113840
D parsers do not support @code{%destructor}, since the language
1383213841
adopts garbage collection. The parser will try to hold references
1383313842
to semantic values for as little time as needed.
1383413843

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
1383813850

1383913851

1384013852
@node D Location Values
@@ -13881,15 +13893,15 @@ The superclass and the implemented
1388113893
interfaces of the parser class can be specified with the @code{%define
1388213894
api.parser.extends} and @samp{%define api.parser.implements} directives.
1388313895

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
1388713899
below, all the other members and fields are preceded with a @code{yy} or
1388813900
@code{YY} prefix to avoid clashes with user code.
1388913901

1389013902
The parser class can be extended using the @code{%parse-param}
1389113903
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.
1389313905

1389413906
@deftypeop {Constructor} {YYParser} {} this(@var{lex_param}, @dots{}, @var{parse_param}, @dots{})
1389513907
Build a new parser object with embedded @code{%code lexer}. There are
@@ -14012,7 +14024,7 @@ invoke @samp{%define parse.error custom}.
1401214024

1401314025
@defcv {Type} {YYParser} {SymbolKind}
1401414026
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
1401614028
the symbol names.
1401714029
@end defcv
1401814030

@@ -14135,6 +14147,61 @@ errors. This is useful primarily in error rules.
1413514147
@xref{Error Recovery}.
1413614148
@end deffn
1413714149

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+
1413814205
@node Java Parsers
1413914206
@section Java Parsers
1414014207

@@ -14146,7 +14213,7 @@ errors. This is useful primarily in error rules.
1414614213
* Java Parser Context Interface:: Circumstances of a syntax error
1414714214
* Java Scanner Interface:: Specifying the scanner for the parser
1414814215
* 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
1415014217
* Java Differences:: Differences between C/C++ and Java Grammars
1415114218
* Java Declarations Summary:: List of Bison declarations used with Java
1415214219
@end menu
@@ -14313,7 +14380,7 @@ below, all the other members and fields are preceded with a @code{yy} or
1431314380
The parser class can be extended using the @code{%parse-param}
1431414381
directive. Each occurrence of the directive will add a @code{protected
1431514382
final} field to the parser class, and an argument to its constructor,
14316-
which initialize them automatically.
14383+
which initializes them automatically.
1431714384

1431814385
@deftypeop {Constructor} {YYParser} {} YYParser (@var{lex_param}, @dots{}, @var{parse_param}, @dots{})
1431914386
Build a new parser object with embedded @code{%code lexer}. There are

0 commit comments

Comments
 (0)