aboutsummaryrefslogtreecommitdiff
path: root/src/tools/check_bison_recursion.pl
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools/check_bison_recursion.pl')
-rwxr-xr-xsrc/tools/check_bison_recursion.pl82
1 files changed, 49 insertions, 33 deletions
diff --git a/src/tools/check_bison_recursion.pl b/src/tools/check_bison_recursion.pl
index f350b26992e..142a7839bd0 100755
--- a/src/tools/check_bison_recursion.pl
+++ b/src/tools/check_bison_recursion.pl
@@ -32,43 +32,59 @@ my $cur_nonterminal;
# We parse the input and emit warnings on the fly.
my $in_grammar = 0;
-while (<>) {
- my $rule_number;
- my $rhs;
+while (<>)
+{
+ my $rule_number;
+ my $rhs;
- # We only care about the "Grammar" part of the input.
- if (m/^Grammar$/) {
- $in_grammar = 1;
- } elsif (m/^Terminal/) {
- $in_grammar = 0;
- } elsif ($in_grammar) {
- if (m/^\s*(\d+)\s+(\S+):\s+(.*)$/) {
- # first rule for nonterminal
- $rule_number = $1;
- $cur_nonterminal = $2;
- $rhs = $3;
- } elsif (m/^\s*(\d+)\s+\|\s+(.*)$/) {
- # additional rule for nonterminal
- $rule_number = $1;
- $rhs = $2;
+ # We only care about the "Grammar" part of the input.
+ if (m/^Grammar$/)
+ {
+ $in_grammar = 1;
}
- }
+ elsif (m/^Terminal/)
+ {
+ $in_grammar = 0;
+ }
+ elsif ($in_grammar)
+ {
+ if (m/^\s*(\d+)\s+(\S+):\s+(.*)$/)
+ {
+
+ # first rule for nonterminal
+ $rule_number = $1;
+ $cur_nonterminal = $2;
+ $rhs = $3;
+ }
+ elsif (m/^\s*(\d+)\s+\|\s+(.*)$/)
+ {
+
+ # additional rule for nonterminal
+ $rule_number = $1;
+ $rhs = $2;
+ }
+ }
+
+ # Process rule if we found one
+ if (defined $rule_number)
+ {
+
+ # deconstruct the RHS
+ $rhs =~ s|^/\* empty \*/$||;
+ my @rhs = split '\s', $rhs;
+ print "Rule $rule_number: $cur_nonterminal := @rhs\n" if $debug;
- # Process rule if we found one
- if (defined $rule_number) {
- # deconstruct the RHS
- $rhs =~ s|^/\* empty \*/$||;
- my @rhs = split '\s', $rhs;
- print "Rule $rule_number: $cur_nonterminal := @rhs\n" if $debug;
- # We complain if the nonterminal appears as the last RHS element
- # but not elsewhere, since "expr := expr + expr" is reasonable
- my $lastrhs = pop @rhs;
- if (defined $lastrhs &&
- $cur_nonterminal eq $lastrhs &&
- !grep { $cur_nonterminal eq $_ } @rhs) {
- print "Right recursion in rule $rule_number: $cur_nonterminal := $rhs\n";
+ # We complain if the nonterminal appears as the last RHS element
+ # but not elsewhere, since "expr := expr + expr" is reasonable
+ my $lastrhs = pop @rhs;
+ if ( defined $lastrhs
+ && $cur_nonterminal eq $lastrhs
+ && !grep { $cur_nonterminal eq $_ } @rhs)
+ {
+ print
+"Right recursion in rule $rule_number: $cur_nonterminal := $rhs\n";
+ }
}
- }
}
exit 0;