examples: shorten the name of the calc++ files

* doc/bison.texi: Turn the calc++- prefix into calc++/.
* examples/extexi (%file_wanted): Replace with
(&file_wanted): this.
* examples/calc++/local.mk: Adjust.
This commit is contained in:
Akim Demaille
2018-08-23 08:42:00 +02:00
parent 9645a2b20e
commit 3fda8335bf
5 changed files with 85 additions and 81 deletions

View File

@@ -11113,18 +11113,17 @@ the file for parsing, instantiate the parser etc.), we recommend
transforming the simple parsing context structure into a fully blown transforming the simple parsing context structure into a fully blown
@dfn{parsing driver} class. @dfn{parsing driver} class.
The declaration of this driver class, @file{calc++-driver.hh}, is as The declaration of this driver class, in @file{driver.hh}, is as follows. The
follows. The first part includes the CPP guard and imports the first part includes the CPP guard and imports the required standard library
required standard library components, and the declaration of the parser components, and the declaration of the parser class.
class.
@comment file: calc++-driver.hh @comment file: calc++/driver.hh
@example @example
#ifndef CALCXX_DRIVER_HH #ifndef DRIVER_HH
# define CALCXX_DRIVER_HH # define DRIVER_HH
# include <string> # include <string>
# include <map> # include <map>
# include "calc++-parser.hh" # include "parser.hh"
@end example @end example
@@ -11134,7 +11133,7 @@ the signature of @code{yylex} to be defined in the macro
@code{YY_DECL}, and the C++ parser expects it to be declared. We can @code{YY_DECL}, and the C++ parser expects it to be declared. We can
factor both as follows. factor both as follows.
@comment file: calc++-driver.hh @comment file: calc++/driver.hh
@example @example
// Tell Flex the lexer's prototype ... // Tell Flex the lexer's prototype ...
# define YY_DECL \ # define YY_DECL \
@@ -11147,7 +11146,7 @@ YY_DECL;
The @code{calcxx_driver} class is then declared with its most obvious The @code{calcxx_driver} class is then declared with its most obvious
members. members.
@comment file: calc++-driver.hh @comment file: calc++/driver.hh
@example @example
// Conducting the whole scanning and parsing of Calc++. // Conducting the whole scanning and parsing of Calc++.
class calcxx_driver class calcxx_driver
@@ -11165,7 +11164,7 @@ public:
To encapsulate the coordination with the Flex scanner, it is useful to have To encapsulate the coordination with the Flex scanner, it is useful to have
member functions to open and close the scanning phase. member functions to open and close the scanning phase.
@comment file: calc++-driver.hh @comment file: calc++/driver.hh
@example @example
// Handling the scanner. // Handling the scanner.
void scan_begin (); void scan_begin ();
@@ -11176,7 +11175,7 @@ member functions to open and close the scanning phase.
@noindent @noindent
Similarly for the parser itself. Similarly for the parser itself.
@comment file: calc++-driver.hh @comment file: calc++/driver.hh
@example @example
// Run the parser on file F. // Run the parser on file F.
// Return 0 on success. // Return 0 on success.
@@ -11194,13 +11193,13 @@ dumping them on the standard error output, we will pass them to the
compiler driver using the following two member functions. Finally, we compiler driver using the following two member functions. Finally, we
close the class declaration and CPP guard. close the class declaration and CPP guard.
@comment file: calc++-driver.hh @comment file: calc++/driver.hh
@example @example
// Error handling. // Error handling.
void error (const yy::location& l, const std::string& m); void error (const yy::location& l, const std::string& m);
void error (const std::string& m); void error (const std::string& m);
@}; @};
#endif // ! CALCXX_DRIVER_HH #endif // ! DRIVER_HH
@end example @end example
The implementation of the driver is straightforward. The @code{parse} The implementation of the driver is straightforward. The @code{parse}
@@ -11208,10 +11207,10 @@ member function deserves some attention. The @code{error} functions
are simple stubs, they should actually register the located error are simple stubs, they should actually register the located error
messages and set error state. messages and set error state.
@comment file: calc++-driver.cc @comment file: calc++/driver.cc
@example @example
#include "calc++-driver.hh" #include "driver.hh"
#include "calc++-parser.hh" #include "parser.hh"
calcxx_driver::calcxx_driver () calcxx_driver::calcxx_driver ()
: trace_scanning (false), trace_parsing (false) : trace_scanning (false), trace_parsing (false)
@@ -11252,13 +11251,12 @@ calcxx_driver::error (const std::string& m)
@node Calc++ Parser @node Calc++ Parser
@subsubsection Calc++ Parser @subsubsection Calc++ Parser
The grammar file @file{calc++-parser.yy} starts by asking for the C++ The grammar file @file{parser.yy} starts by asking for the C++ deterministic
deterministic parser skeleton, the creation of the parser header file, parser skeleton, the creation of the parser header file, and specifies the
and specifies the name of the parser class. Because the C++ skeleton name of the parser class. Because the C++ skeleton changed several times,
changed several times, it is safer to require the version you designed it is safer to require the version you designed the grammar for.
the grammar for.
@comment file: calc++-parser.yy @comment file: calc++/parser.yy
@example @example
%skeleton "lalr1.cc" /* -*- C++ -*- */ %skeleton "lalr1.cc" /* -*- C++ -*- */
%require "@value{VERSION}" %require "@value{VERSION}"
@@ -11274,7 +11272,7 @@ require the variant-based interface. To make sure we properly use it, we
enable assertions. To fully benefit from type-safety and more natural enable assertions. To fully benefit from type-safety and more natural
definition of ``symbol'', we enable @code{api.token.constructor}. definition of ``symbol'', we enable @code{api.token.constructor}.
@comment file: calc++-parser.yy @comment file: calc++/parser.yy
@example @example
%define api.token.constructor %define api.token.constructor
%define api.value.type variant %define api.value.type variant
@@ -11291,7 +11289,7 @@ driver's header needs detailed knowledge about the parser class (in
particular its inner types), it is the parser's header which will use a particular its inner types), it is the parser's header which will use a
forward declaration of the driver. @xref{%code Summary}. forward declaration of the driver. @xref{%code Summary}.
@comment file: calc++-parser.yy @comment file: calc++/parser.yy
@example @example
%code requires %code requires
@{ @{
@@ -11305,7 +11303,7 @@ The driver is passed by reference to the parser and to the scanner.
This provides a simple but effective pure interface, not relying on This provides a simple but effective pure interface, not relying on
global variables. global variables.
@comment file: calc++-parser.yy @comment file: calc++/parser.yy
@example @example
// The parsing context. // The parsing context.
%param @{ calcxx_driver& driver @} %param @{ calcxx_driver& driver @}
@@ -11317,7 +11315,7 @@ first location's file name. Afterward new locations are computed
relatively to the previous locations: the file name will be relatively to the previous locations: the file name will be
propagated. propagated.
@comment file: calc++-parser.yy @comment file: calc++/parser.yy
@example @example
%locations %locations
%initial-action %initial-action
@@ -11332,7 +11330,7 @@ Use the following two directives to enable parser tracing and verbose error
messages. However, verbose error messages can contain incorrect information messages. However, verbose error messages can contain incorrect information
(@pxref{LAC}). (@pxref{LAC}).
@comment file: calc++-parser.yy @comment file: calc++/parser.yy
@example @example
%define parse.trace %define parse.trace
%define parse.error verbose %define parse.error verbose
@@ -11343,11 +11341,11 @@ messages. However, verbose error messages can contain incorrect information
The code between @samp{%code @{} and @samp{@}} is output in the The code between @samp{%code @{} and @samp{@}} is output in the
@file{*.cc} file; it needs detailed knowledge about the driver. @file{*.cc} file; it needs detailed knowledge about the driver.
@comment file: calc++-parser.yy @comment file: calc++/parser.yy
@example @example
%code %code
@{ @{
# include "calc++-driver.hh" # include "driver.hh"
@} @}
@end example @end example
@@ -11359,7 +11357,7 @@ allows for nicer error messages referring to ``end of file'' instead of
avoid name clashes in the generated files (@pxref{Calc++ Scanner}), prefix avoid name clashes in the generated files (@pxref{Calc++ Scanner}), prefix
tokens with @code{TOK_} (@pxref{%define Summary,,api.token.prefix}). tokens with @code{TOK_} (@pxref{%define Summary,,api.token.prefix}).
@comment file: calc++-parser.yy @comment file: calc++/parser.yy
@example @example
%define api.token.prefix @{TOK_@} %define api.token.prefix @{TOK_@}
%token %token
@@ -11379,7 +11377,7 @@ Since we use variant-based semantic values, @code{%union} is not used, and
both @code{%type} and @code{%token} expect genuine types, as opposed to type both @code{%type} and @code{%token} expect genuine types, as opposed to type
tags. tags.
@comment file: calc++-parser.yy @comment file: calc++/parser.yy
@example @example
%token <std::string> IDENTIFIER "identifier" %token <std::string> IDENTIFIER "identifier"
%token <int> NUMBER "number" %token <int> NUMBER "number"
@@ -11392,7 +11390,7 @@ recovery; the memory, for strings for instance, will be reclaimed by the
regular destructors. All the values are printed using their regular destructors. All the values are printed using their
@code{operator<<} (@pxref{Printer Decl, , Printing Semantic Values}). @code{operator<<} (@pxref{Printer Decl, , Printing Semantic Values}).
@comment file: calc++-parser.yy @comment file: calc++/parser.yy
@example @example
%printer @{ yyoutput << $$; @} <*>; %printer @{ yyoutput << $$; @} <*>;
@end example @end example
@@ -11401,7 +11399,7 @@ regular destructors. All the values are printed using their
The grammar itself is straightforward (@pxref{Location Tracking Calc, , The grammar itself is straightforward (@pxref{Location Tracking Calc, ,
Location Tracking Calculator - @code{ltcalc}}). Location Tracking Calculator - @code{ltcalc}}).
@comment file: calc++-parser.yy @comment file: calc++/parser.yy
@example @example
%% %%
%start unit; %start unit;
@@ -11431,7 +11429,7 @@ exp:
Finally the @code{error} member function registers the errors to the Finally the @code{error} member function registers the errors to the
driver. driver.
@comment file: calc++-parser.yy @comment file: calc++/parser.yy
@example @example
void void
yy::calcxx_parser::error (const location_type& l, yy::calcxx_parser::error (const location_type& l,
@@ -11447,15 +11445,15 @@ yy::calcxx_parser::error (const location_type& l,
The Flex scanner first includes the driver declaration, then the The Flex scanner first includes the driver declaration, then the
parser's to get the set of defined tokens. parser's to get the set of defined tokens.
@comment file: calc++-scanner.ll @comment file: calc++/scanner.ll
@example @example
%@{ /* -*- C++ -*- */ %@{ /* -*- C++ -*- */
# include <cerrno> # include <cerrno>
# include <climits> # include <climits>
# include <cstdlib> # include <cstdlib>
# include <string> # include <string>
# include "calc++-driver.hh" # include "driver.hh"
# include "calc++-parser.hh" # include "parser.hh"
// Work around an incompatibility in flex (at least versions // Work around an incompatibility in flex (at least versions
// 2.5.31 through 2.5.33): it generates code that does // 2.5.31 through 2.5.33): it generates code that does
@@ -11481,7 +11479,7 @@ Because there is no @code{#include}-like feature we don't need
actual file, this is not an interactive session with the user. actual file, this is not an interactive session with the user.
Finally, we enable scanner tracing. Finally, we enable scanner tracing.
@comment file: calc++-scanner.ll @comment file: calc++/scanner.ll
@example @example
%option noyywrap nounput batch debug noinput %option noyywrap nounput batch debug noinput
@end example @end example
@@ -11489,7 +11487,7 @@ Finally, we enable scanner tracing.
@noindent @noindent
Abbreviations allow for more readable rules. Abbreviations allow for more readable rules.
@comment file: calc++-scanner.ll @comment file: calc++/scanner.ll
@example @example
id [a-zA-Z][a-zA-Z_0-9]* id [a-zA-Z][a-zA-Z_0-9]*
int [0-9]+ int [0-9]+
@@ -11505,7 +11503,7 @@ cursor is adjusted, and each time blanks are matched, the begin cursor
is moved onto the end cursor to effectively ignore the blanks is moved onto the end cursor to effectively ignore the blanks
preceding tokens. Comments would be treated equally. preceding tokens. Comments would be treated equally.
@comment file: calc++-scanner.ll @comment file: calc++/scanner.ll
@example @example
@group @group
%@{ %@{
@@ -11527,7 +11525,7 @@ preceding tokens. Comments would be treated equally.
@noindent @noindent
The rules are simple. The driver is used to report errors. The rules are simple. The driver is used to report errors.
@comment file: calc++-scanner.ll @comment file: calc++/scanner.ll
@example @example
"-" return yy::calcxx_parser::make_MINUS (loc); "-" return yy::calcxx_parser::make_MINUS (loc);
"+" return yy::calcxx_parser::make_PLUS (loc); "+" return yy::calcxx_parser::make_PLUS (loc);
@@ -11556,7 +11554,7 @@ The rules are simple. The driver is used to report errors.
Finally, because the scanner-related driver's member-functions depend Finally, because the scanner-related driver's member-functions depend
on the scanner's data, it is simpler to implement them in this file. on the scanner's data, it is simpler to implement them in this file.
@comment file: calc++-scanner.ll @comment file: calc++/scanner.ll
@example @example
@group @group
void void
@@ -11590,7 +11588,7 @@ The top level file, @file{calc++.cc}, poses no problem.
@comment file: calc++.cc @comment file: calc++.cc
@example @example
#include <iostream> #include <iostream>
#include "calc++-driver.hh" #include "driver.hh"
@group @group
int int

View File

@@ -2,18 +2,18 @@
/*.tmp /*.tmp
/.deps /.deps
/calc++ /calc++
/calc++-driver.cc
/calc++-driver.hh
/calc++-parser.cc
/calc++-parser.hh
/calc++-parser.output
/calc++-parser.stamp
/calc++-parser.yy
/calc++-scanner.cc
/calc++-scanner.ll
/calc++.cc /calc++.cc
/calc++.exe /calc++.exe
/calc.stamp /calc.stamp
/driver.cc
/driver.hh
/location.hh /location.hh
/parser.cc
/parser.hh
/parser.output
/parser.stamp
/parser.yy
/position.hh /position.hh
/scanner.cc
/scanner.ll
/stack.hh /stack.hh

View File

@@ -20,7 +20,7 @@
# Don't depend on $(BISON) otherwise we would rebuild these files # Don't depend on $(BISON) otherwise we would rebuild these files
# in srcdir, including during distcheck, which is forbidden. # in srcdir, including during distcheck, which is forbidden.
%D%/calc++-parser.stamp: $(BISON_IN) %D%/parser.stamp: $(BISON_IN)
SUFFIXES += .yy .stamp SUFFIXES += .yy .stamp
.yy.stamp: .yy.stamp:
$(AM_V_YACC)rm -f $@ $(AM_V_YACC)rm -f $@
@@ -28,14 +28,14 @@ SUFFIXES += .yy .stamp
$(AM_V_at)$(YACCCOMPILE) -o $*.cc $< $(AM_V_at)$(YACCCOMPILE) -o $*.cc $<
$(AM_V_at)mv -f $@.tmp $@ $(AM_V_at)mv -f $@.tmp $@
$(calcxx_sources_generated): %D%/calc++-parser.stamp $(calcxx_sources_generated): %D%/parser.stamp
@test -f $@ || rm -f %D%/calc++-parser.stamp @test -f $@ || rm -f %D%/parser.stamp
@test -f $@ || $(MAKE) $(AM_MAKEFLAGS) %D%/calc++-parser.stamp @test -f $@ || $(MAKE) $(AM_MAKEFLAGS) %D%/parser.stamp
CLEANFILES += \ CLEANFILES += \
$(calcxx_sources_generated) \ $(calcxx_sources_generated) \
%D%/calc++-parser.output \ %D%/parser.output \
%D%/calc++-parser.stamp \ %D%/parser.stamp \
%D%/calc++-scanner.cc %D%/scanner.cc
## -------------------- ## ## -------------------- ##
@@ -45,18 +45,18 @@ CLEANFILES += \
# Avoid using BUILT_SOURCES which is too global. # Avoid using BUILT_SOURCES which is too global.
$(%C%_calc___OBJECTS): $(calcxx_sources_generated) $(%C%_calc___OBJECTS): $(calcxx_sources_generated)
calcxx_sources_extracted = \ calcxx_sources_extracted = \
%D%/calc++-driver.cc \ %D%/driver.cc \
%D%/calc++-driver.hh \ %D%/driver.hh \
%D%/calc++-scanner.ll \ %D%/scanner.ll \
%D%/calc++.cc %D%/calc++.cc
calcxx_extracted = \ calcxx_extracted = \
$(calcxx_sources_extracted) \ $(calcxx_sources_extracted) \
%D%/calc++-parser.yy %D%/parser.yy
extracted += $(calcxx_extracted) extracted += $(calcxx_extracted)
calcxx_sources_generated = \ calcxx_sources_generated = \
%D%/calc++-parser.cc \ %D%/parser.cc \
%D%/calc++-parser.hh \ %D%/parser.hh \
%D%/location.hh \ %D%/location.hh \
%D%/position.hh \ %D%/position.hh \
%D%/stack.hh %D%/stack.hh

View File

@@ -1,6 +0,0 @@
// Work around an Automake 1.11.2 bug: it asks for the creation of
// y.tab.c and y.tab.h and then renames them as calc++-parser.cc and
// calc++-parser.h, but in the former it does not convert the
// #include "y.tab.h". We don't want this to show in the
// documentation.
#include "calc++-parser.hh"

View File

@@ -65,8 +65,21 @@ sub message($)
} }
} }
# basename => full file name for files we should extract. # The list of files we should extract.
my %file_wanted; my @file_wanted;
# Whether we should extract that file, and then under which path.
sub file_wanted ($)
{
my ($f) = @_;
for my $file (@file_wanted)
{
# No endswith in Perl 5...
return $file if $f eq substr($file, -length($f));
}
undef
}
sub process ($) sub process ($)
{ {
@@ -89,9 +102,9 @@ sub process ($)
{ {
my $f = $1; my $f = $1;
$block = $2 || 1; $block = $2 || 1;
if ($file_wanted{$f}) if (file_wanted($f))
{ {
$file = $file_wanted{$f}; $file = file_wanted($f);
message(" GEN $file"); message(" GEN $file");
} }
else else
@@ -142,8 +155,7 @@ for my $arg (@ARGV)
{ {
if ($seen_dash) if ($seen_dash)
{ {
use File::Basename; push @file_wanted, $arg;
$file_wanted{basename($arg)} = $arg;
} }
elsif ($arg eq '--') elsif ($arg eq '--')
{ {