SWM ISO c/C++ parser library / class

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Rick

    SWM ISO c/C++ parser library / class

    .... must be able and willing to convert a slew of c/c++ and associated files
    into tokens -- preferably into XML.

    Hi folks. I've had no luck going down the BNF or YACC route on this one.
    Is there a class out there which can take a file / number of files as
    parameters and spew me an XML stream or file? This is simply going to be
    used in a tool to add code in source for a client's project. I was going to
    use regexes for this, but wanted to explore this route first.

    I also realize how monumental this request may be. Just wanted to know if
    the work has already been done.


  • llewelly

    #2
    Re: SWM ISO c/C++ parser library / class

    "Rick" <umop@psyon.org > writes:
    [color=blue]
    > ... must be able and willing to convert a slew of c/c++ and associated files
    > into tokens -- preferably into XML.[/color]

    You might find what you need in the gcc_xml project. Note that it
    doesn't handle function bodies.
    GCC-XML is an XML output extension to the C++ front-end of GCC.

    [color=blue]
    >
    > Hi folks. I've had no luck going down the BNF or YACC route on this
    > one.[/color]

    I can't tell how far you want to go with this. Do you want complete
    parsing, or will something partial and sloppy like what Doxygen
    does do? C++ in particular is viewed as one of the hardest
    languages to parse correctly.

    For complete parsing, C is parse-able with YACC, but C++ is hostile
    to YACC or any other LALR tool. I think with C++ you
    are better off either trimming down your needs until you can
    survive with just regex and no real parsing, or you should try to
    write a recursive descent parser. (The gcc-3.4 (but not the
    gcc_xml) parser is recursive decent.)




    Comment

    • Attila Feher

      #3
      Re: SWM ISO c/C++ parser library / class

      llewelly wrote:
      [SNIP][color=blue]
      > For complete parsing, C is parse-able with YACC, but C++ is hostile
      > to YACC or any other LALR tool. I think with C++ you
      > are better off either trimming down your needs until you can
      > survive with just regex and no real parsing, or you should try to
      > write a recursive descent parser. (The gcc-3.4 (but not the
      > gcc_xml) parser is recursive decent.)[/color]

      This seems to handle C++ parsing, or at least they are in the process of
      making the C++ BNF for it: http://www.codeworker.org

      --
      Attila aka WW


      Comment

      Working...