Re: about H file parser for standard C

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Hello,

> I think you all have the experience to do the following things:

this is not an easy thing to do, and i think very few people here know how
to do it cause it's not a job
of an application developer, what you described is the job of a compiler
writer / language designer ..

if you want to do it yourself you have to make yourself familiar with
regular expressions and grammar parsing of languages (using BNF)

there're some tools that can assist you with this, namely
flex (gnu project) - which is able to generate a C program out of a regular
expression specification
and
bison (also from gnu) - which is able to generate a language parser out of a
grammar (BNF) specification ..

there are more tools for language parsing ..

but these were the two i used to generate an C struct source to source
translator for MS Visual FoxPro (an interpreted xBase language)
but it has taken me about 6 months, and about 3 months of studying first to
get an overview how a compiler works under the hood, and it was far from
beeing easy ...

and this tool even not has the features you'll need because it can't handle
complete header files .. and also doesn't provide a C preprocessor ... so
one has to substitute the preprocessor definition by hand with their actual
values ..

you may come around the preprocessor issue by
instructing your C preprocessor to store the preprocessed headers to other
files

another way to do it might be to automate the MS VC development IDE,
the IDE has a object hierarchy with which you can access the actual code it
has parsed and as long as i know it is COM automatable so you may be able to
write some algorithms to traverse each structure object and output the
according C code

this is definitly not a shareware kind of app, and your project has to be
BIG so the time you invest to implement it yourself pays off in the end ..

Regards
Christian





.



Relevant Pages

  • Re: Cpp Considered Harmful
    ... > One is to present the 'raw' interface of the template to the user. ... easier than they can parse the underlying language itself. ... resulting from the preprocessor, it merely has to preprocess it. ... > Using JBuilder, and the Java counterpart, I can fly through XML ...
    (comp.lang.cpp)
  • Re: Cpp Considered Harmful
    ... ordering, template declaration instantiation, etc.. ... I think you have a serious misunderstanding of the preprocessor. ... Parsing Java is quite a bit simpler than parsing C++. ... >> source code much easier than they can parse the underlying language ...
    (comp.lang.cpp)
  • Re: Cpp Considered Harmful
    ... That is why assertions are preproccessed away in production code. ... What I've seen done with Java IDEs has shown me that they can ... In C++, because of the preprocessor, you cannot really be sure that what ... that you apparently want to enforce coding policy by language design. ...
    (comp.lang.cpp)
  • Multiple #defines in WinError.h
    ... I am binding into the Win32 API from another language. ... with the header files, but must make my own definition modules. ... As I understand the preprocessor it should make the substitutions ...
    (comp.programming)
  • Re: Boost Workshop at OOPSLA 2004
    ... There is only one replacement for the c++ preprocessor which I would ... the near future: metacode. ... By this I mean the capability to walk the parse tree at compile time ... proposal but a full language extension). ...
    (comp.lang.cpp)