sub directives($@)
{
- my ($bench, @directives) = @_;
+ my ($bench, @directive) = @_;
my $res = "/* Directives for bench `$bench'. */\n";
- for my $d (@directives)
+ for my $d (@directive)
{
$res .= $d . "\n"
unless $d eq '%variant';
return $res;
}
-=item C<triangular_grammar ($base, $max, @directives)>
+=item C<triangular_grammar ($base, $max, @directive)>
Create a large triangular grammar which looks like :
C<$base> is the base name for the file to create (F<$base.y>).
C<$max> is the number of such rules (here, 5). You may pass
-additional Bison C<@directives>.
+additional Bison C<@directive>.
The created parser is self contained: it includes its scanner, and
source of input.
sub triangular_grammar ($$$)
{
- my ($base, $max, @directives) = @_;
- my $directives = directives ($base, @directives);
+ my ($base, $max, @directive) = @_;
+ my $directives = directives ($base, @directive);
my $out = new IO::File ">$base.y"
or die;
}
##################################################################
-=item C<calc_grammar ($base, $max, @directives)>
+=item C<calc_grammar ($base, $max, @directive)>
Generate a Bison file F<$base.y> for a calculator parser in C. Pass
-the additional Bison C<@directives>. C<$max> is ignored, but left to
+the additional Bison C<@directive>. C<$max> is ignored, but left to
have the same interface as C<triangular_grammar>.
=cut
sub calc_grammar ($$$)
{
- my ($base, $max, @directives) = @_;
- my $directives = directives ($base, @directives);
+ my ($base, $max, @directive) = @_;
+ my $directives = directives ($base, @directive);
my $out = new IO::File ">$base.y"
or die;
##################################################################
-=item C<variant_grammar ($base, $max, @directives)>
+=item C<variant_grammar ($base, $max, @directive)>
Generate a Bison file F<$base.y> that uses, or not, the Boost.Variants
-depending on the C<@directives>.
+depending on the C<@directive>.
=cut
sub variant_grammar ($$$)
{
- my ($base, $max, @directives) = @_;
- my $directives = directives ($base, @directives);
- my $variant = grep { '%variant' } @directives;
+ my ($base, $max, @directive) = @_;
+ my $directives = directives ($base, @directive);
+ my $variant = grep { $_ eq '%variant' } @directive;
my $out = new IO::File ">$base.y"
or die;
print $out <<EOF;
-%debug
%language "C++"
%defines
+$directives
-%code requires // code for the .hh file
+%code requires // variant.h
{
#include <string>
}
-%code // code for the .cc file
+%code // variant.c
{
#include <algorithm>
#include <iostream>
int main(int argc, char *argv[])
{
yy::parser p;
+#if YYDEBUG
p.set_debug_level(!!getenv("YYDEBUG"));
+#endif
p.parse();
return 0;
}
Generate benches for C<$gram>. C<$gram> should be C<calc> or
C<triangle>. C<%bench> is a hash of the form:
- $name => @directives
+ $name => @directive
-where C<$name> is the name of the bench, and C<@directives> are the
+where C<$name> is the name of the bench, and C<@directive> are the
Bison directive to use for this bench. All the benches are compared
against each other, repeated 50 times.
# Call the Bison input file generator.
my $generator = "$gram" . "_grammar";
&$generator ($name, 200, @$directives);
+ # Compile the executable.
compile ($name);
$bench{$name} = "system ('./$name');";
chop($size{$name} = `wc -c <$name`);
bench_grammar
('variant',
(
- "union" => [],
- "variant" => ['%variant'],
+ "union" => [],
+ "variant" => ['%variant'],
+ "union-debug" => ['%debug'],
+ "variant-debug" => ['%debug', '%variant'],
)
);
}