in reply to Re: Parsing a .h header file
in thread Parsing a .h header file

With reference to my problem that I have described : here:

A possible solution to the problem *could* be :

1) I use the same method I use now to create a tokenzied sorta intermediate file from the header file complete with all the information that I need to be able to furnish a class declaration and a class definition.Call this File A

Use File A as an input file to further process the tokens etc and produce another file that has tags/tokens whatever else that I need for stuff like:

-function names

-function params

return values

and so on WITHOUT any formatting.CAll it File B

3)Use File B and parse each token to get File C. While priting out File C, I check for the length of the line being printed (to the file) and if the length exceeds 78 characters, I insert a newline to move to the next line.

Possible problems that I encounter or envisage I will encouter are:

1) Within functions etc, one normally indents the code, so also in if/for code blocks, so when Im processing a string of tokens that I know is ised for a function definition, after I move to a newline, i SHOULD also print out a tab to preserve the formatting

This is all I can think of at the moment and I am rather confused by all this. I thought it was an easy problem to begin with , but.....:(

Replies are listed 'Best First'.
Re: Re: Re: Parsing a .h header file
by clscott (Friar) on Oct 22, 2003 at 19:43 UTC
    I did a quick google search for 'parse C++ header file with perl' and came up with quite a few good results. My suggestion is that you:
    • find a script that already generates a data structure from a header file ( like this one: http://starship.python.net/crew/tbryan/PERCEPS/ ) ( or http://aips2.nrao.edu/RELEASED/cxx2html/ )
    • use Data::Dumper to view the data structure that is created.
    • use a templating system such as Template toolkit to layout your functions and classes.

    This way you will be able to take an iterative approach to the development of your tool and it is a good method to build your perl skills as you go.

    --
    Clayton
Re: Re: Re: Parsing a .h header file
by hehenoobhehe (Novice) on Oct 22, 2003 at 09:39 UTC
    Would appreciate if you comment on the misgivings of this possible solution as I have suggested here. Thanks

      I would generate the code with no indenting and potential overlength lines then run it through astyle to make it presentable. Link to astyle on the previous node.

      cheers

      tachyon

      s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print