mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 04:13:03 +00:00
Bench: syntactic sugar for %define/#define.
* etc/bench.pl.in (parse_dirs): Support %d and #d with arguments. (&bench_push_parser, bench_variant_parser): Use this feature. (&eat): New. Use it.
This commit is contained in:
@@ -1,3 +1,11 @@
|
|||||||
|
2008-11-11 Akim Demaille <demaille@gostai.com>
|
||||||
|
|
||||||
|
Bench: syntactic sugar for %define/#define.
|
||||||
|
* etc/bench.pl.in (parse_dirs): Support %d and #d with arguments.
|
||||||
|
(&bench_push_parser, bench_variant_parser): Use this feature.
|
||||||
|
(&eat): New.
|
||||||
|
Use it.
|
||||||
|
|
||||||
2008-11-11 Akim Demaille <demaille@gostai.com>
|
2008-11-11 Akim Demaille <demaille@gostai.com>
|
||||||
|
|
||||||
Less memory pressure on the "list" bench.
|
Less memory pressure on the "list" bench.
|
||||||
|
|||||||
@@ -35,8 +35,9 @@ I<directives>:
|
|||||||
| directives & directives -- Concatenation
|
| directives & directives -- Concatenation
|
||||||
| [ directives> ] -- Optional
|
| [ directives> ] -- Optional
|
||||||
| ( directives> ) -- Parentheses
|
| ( directives> ) -- Parentheses
|
||||||
|
| #d NAME[=VALUE] -- %code { #define NAME [VALUE] }
|
||||||
|
| %d NAME[=VALUE] -- %define NAME ["VALUE"]
|
||||||
| %s skeleton -- %skeleton "skeleton"
|
| %s skeleton -- %skeleton "skeleton"
|
||||||
| #d definition -- %code { #define definition }
|
|
||||||
| directive
|
| directive
|
||||||
|
|
||||||
Parentheses only group to override precedence. For instance:
|
Parentheses only group to override precedence. For instance:
|
||||||
@@ -872,10 +873,10 @@ interfaces.
|
|||||||
sub bench_push_parser ()
|
sub bench_push_parser ()
|
||||||
{
|
{
|
||||||
bench ('calc',
|
bench ('calc',
|
||||||
(
|
qw(
|
||||||
'[', '%define api.pure', ']',
|
[ %d api.pure ]
|
||||||
'&',
|
&
|
||||||
'[', '%define api.push_pull "both"', ']'
|
[ %d api.push_pull=both ]
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -891,11 +892,9 @@ sub bench_variant_parser ()
|
|||||||
{
|
{
|
||||||
bench ('list',
|
bench ('list',
|
||||||
qw(
|
qw(
|
||||||
%s lalr1.cc
|
|
||||||
&
|
|
||||||
[ %debug ]
|
[ %debug ]
|
||||||
&
|
&
|
||||||
[ %define variant
|
[ %d variant
|
||||||
&
|
&
|
||||||
[ #d VARIANT_DESTROY ]
|
[ #d VARIANT_DESTROY ]
|
||||||
&
|
&
|
||||||
@@ -939,30 +938,42 @@ sub help ($)
|
|||||||
|
|
||||||
######################################################################
|
######################################################################
|
||||||
|
|
||||||
|
# The end of the directives to parse.
|
||||||
|
my $eod = "end of directives";
|
||||||
# The list of tokens parsed by the following functions.
|
# The list of tokens parsed by the following functions.
|
||||||
my @token;
|
my @token;
|
||||||
|
|
||||||
|
# eat ($EXPECTED)
|
||||||
|
# ---------------
|
||||||
|
# Check that the current token is $EXPECTED, and move to the next.
|
||||||
|
sub eat ($)
|
||||||
|
{
|
||||||
|
my ($expected) = @_;
|
||||||
|
die "expected $expected, unexpected: $token[0] (@token)\n"
|
||||||
|
unless $token[0] eq $expected;
|
||||||
|
shift @token;
|
||||||
|
}
|
||||||
|
|
||||||
# Parse directive specifications:
|
# Parse directive specifications:
|
||||||
# expr: term (| term)*
|
# expr: term (| term)*
|
||||||
# term: fact (& fact)*
|
# term: fact (& fact)*
|
||||||
# fact: ( expr ) | [ expr ] | dirs
|
# fact: ( expr ) | [ expr ] | dirs
|
||||||
# dirs: %s SKELETON | #d DEFINE | directive
|
# dirs: %s SKELETON | #d NAME[=VALUE] | %d NAME[=VALUE] | directive
|
||||||
sub parse (@)
|
sub parse (@)
|
||||||
{
|
{
|
||||||
@token = @_;
|
@token = (@_, $eod);
|
||||||
verbose 3, "Parsing: @token\n";
|
verbose 3, "Parsing: @token\n";
|
||||||
my @res = parse_expr ();
|
my @res = parse_expr ();
|
||||||
die "expected end of directives, unexpected: @token"
|
eat ($eod);
|
||||||
if defined $token[0];
|
|
||||||
return @res;
|
return @res;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub parse_expr ()
|
sub parse_expr ()
|
||||||
{
|
{
|
||||||
my @res = parse_term ();
|
my @res = parse_term ();
|
||||||
while (defined $token[0] && $token[0] eq '|')
|
while ($token[0] eq '|')
|
||||||
{
|
{
|
||||||
shift @token;
|
eat ('|');
|
||||||
# Alternation.
|
# Alternation.
|
||||||
push @res, parse_term ();
|
push @res, parse_term ();
|
||||||
}
|
}
|
||||||
@@ -972,9 +983,9 @@ sub parse_expr ()
|
|||||||
sub parse_term ()
|
sub parse_term ()
|
||||||
{
|
{
|
||||||
my @res = parse_fact ();
|
my @res = parse_fact ();
|
||||||
while (defined $token[0] && $token[0] eq '&')
|
while ($token[0] eq '&')
|
||||||
{
|
{
|
||||||
shift @token;
|
eat ('&');
|
||||||
# Cartesian product.
|
# Cartesian product.
|
||||||
my @lhs = @res;
|
my @lhs = @res;
|
||||||
@res = ();
|
@res = ();
|
||||||
@@ -997,19 +1008,15 @@ sub parse_fact ()
|
|||||||
|
|
||||||
if ($token[0] eq '(')
|
if ($token[0] eq '(')
|
||||||
{
|
{
|
||||||
shift @token;
|
eat ('(');
|
||||||
@res = parse_expr ();
|
@res = parse_expr ();
|
||||||
die "unexpected $token[0], expected )"
|
eat (')');
|
||||||
unless $token[0] eq ')';
|
|
||||||
shift @token;
|
|
||||||
}
|
}
|
||||||
elsif ($token[0] eq '[')
|
elsif ($token[0] eq '[')
|
||||||
{
|
{
|
||||||
shift @token;
|
eat ('[');
|
||||||
@res = (parse_expr (), '');
|
@res = (parse_expr (), '');
|
||||||
die "unexpected $token[0], expected ]"
|
eat (']');
|
||||||
unless $token[0] eq ']';
|
|
||||||
shift @token;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -1026,8 +1033,16 @@ sub parse_dirs ()
|
|||||||
|
|
||||||
if ($token[0] eq '#d')
|
if ($token[0] eq '#d')
|
||||||
{
|
{
|
||||||
|
eat ('#d');
|
||||||
|
$token[0] =~ s/(.*?)=(.*)/$1 $2/;
|
||||||
|
@res = ("%code {\n#define $token[0]\n}");
|
||||||
shift @token;
|
shift @token;
|
||||||
@res = ("%code {\n#define\n}");
|
}
|
||||||
|
elsif ($token[0] eq '%d')
|
||||||
|
{
|
||||||
|
shift @token;
|
||||||
|
$token[0] =~ s/(.*?)=(.*)/$1 "$2"/;
|
||||||
|
@res = ("%define $token[0]");
|
||||||
shift @token;
|
shift @token;
|
||||||
}
|
}
|
||||||
elsif ($token[0] eq '%s')
|
elsif ($token[0] eq '%s')
|
||||||
|
|||||||
Reference in New Issue
Block a user