in reply to Re: f77 variable list parsing
in thread f77 variable list parsing

"WATFOR Forever!" Anyway, I found an interesting pertinent link: http://marine.rutgers.edu/po/tools/perl.html I also played with your code and incorporated it into my mini project:
sub getFortranVarNames { # # Purpose: Find all variables in a list of FORTRAN declarations. # Preserve any array dimension information as a string for # later processing. Subroutine is based on response by # "Sandy" on perlmonks.org # # Return array is further massaged for array dimensions. my ($string) = @_; my @fields=(); my $open = 0; my $close = 0; my $a; my $i = 0; # \z TRUE at end of string only while (not $string =~ /\G\z/gc) { # --- get variable name # \G TRUE at end-of-match position of prior m//g # ?: cluster only parenthesis, no capturing # gc - allow continued search after failed /g match if ((not $open) and ($string =~ /\G(?:\s*|,)(\w+)/gc)) { $fields[$i]{name}=$1; $fields[$i]{dims}=''; $opt_debug and print "Name: $1\t"; $i++; # --- find opening brackets, and keep track of level } elsif ($string =~ /\G([^\)]*\()/gc) { $a = $1; $open++; } # --- find closing brackets, and print info elsif (($open) and ($string =~/\G\s*([^\(]*\))/gc)) { $opt_debug and print "-> $a$1\n"; $fields[$i-1]{dims}="$a$1"; $open--; } } return (@fields); }
When I get the whole thing done I may post it.

Replies are listed 'Best First'.
Re^3: f77 variable list parsing
by Sandy (Curate) on Jul 05, 2004 at 13:28 UTC
    WatFIV!!

    When I get the whole thing done I may post it.
    Go for it!