There is an already existing Fortran parser for Exubernt CTags. Does
that do what you want?
The way to handle the below situation is to parse the subroutine, then
parse the "stuff" inside as a series of variables before skipping to the
end of the subroutine.
Each parser can have a semantic-tag-expand-function. There are examples
in C++ and Java. Usually this is used to take a compound statement such as:
and turn it into two variable tags. I think it makes sense that you
could take the subroutine with names-only for args, then look at the
:localvariables, and if there are variables of the same name, copy them
up as arguments, and remove them from the :localvariables. Of course,
you'd have to make up some :localvariable attribute and populate it.
Alternately, you could do something similar to the K&R argument parsing
in the C++ grammar, but I'm not quite sure that is a match since those
declarations are not officially in the code block.
On 08/28/2010 02:37 AM, David Engster wrote:
> Since I will have to do some numerical Fortran90 programming, I'd like
> to get basic F90 parsing into Semantic.
> Now, I'm pretty much a newbie when it comes to Bison/Wisent and grammars
> in general. From what I've read, parsing Fortran through a LALR grammar
> is far from straightforward. The only stuff I could find was a grammar
> from the Eli project and an ANTLR grammar.
> However, I'm not aiming at a full grammar - I think it should be enough
> to parse the most basic constructs, like functions, subroutines,
> variables and structures.
> The problem I have is the extraction of type information. An example:
> subroutine mysub(one,two,three)
> implicit none
> integer, intent(in) :: one, two
> double precision, intent(out) :: three
> ... code ...
> end subroutine mysub
> You can see that the type information follows in the subroutine's
> body. The 'intent' parameter specifies if the variables are input or
> output data (Fortran always passes by reference), but this is optional.
> I have no problem parsing the 'subroutine' line, but I obviously don't
> have type information at that time. Can I do this with bison/wisent, or
> do I have to add the type information afterwards in some kind of second
> pass? Should I just skip the grammar stuff and simply do everything
> with regexps?
>  http://eli-project.sourceforge.net/fortran_html/Parse.html
>  http://fortran-parser.sourceforge.net/
> Sell apps to millions through the Intel(R) Atom(Tm) Developer Program
> Be part of this innovative community and reach millions of netbook users
> worldwide. Take advantage of special opportunities to increase revenue and
> speed time-to-market. Join now, and jumpstart your future.
> cedet-semantic mailing list