Java C Parser/Preprocessor

Discussion in 'Java' started by student08, Apr 1, 2008.

  1. student08

    student08 Guest

    Hi I'm currently looking for a C parser/preprocessor that's written in
    Java (since I plan to be using the Prefuse visualisation toolkit) for
    a student project.

    I looked at ANTLR but the gcc translation framework grammar that's
    available on its website is fairly dated and I can't seem to find any
    outside projects which use it and can verify its reliability. Also
    it's only works with already preprocessed C and may not be able to
    emit comments.

    Does anyone know any good C parser and preprocessor tools written in
    Java? Hopefully it is able to use an abstract syntax tree so that I
    can perform my own code transformations easily.
    student08, Apr 1, 2008
    #1
    1. Advertising

  2. student08

    Mark Space Guest

    student08 wrote:
    > Hi I'm currently looking for a C parser/preprocessor that's written in
    > Java (since I plan to be using the Prefuse visualisation toolkit) for
    > a student project.


    Have you looked at these? (First or second link when I Google for "java
    parser").

    <http://java-source.net/open-source/parser-generators>
    Mark Space, Apr 1, 2008
    #2
    1. Advertising

  3. student08

    Roedy Green Guest

    On Mon, 31 Mar 2008 23:26:45 -0700 (PDT), student08
    <> wrote, quoted or indirectly quoted someone who
    said :

    >
    >Does anyone know any good C parser and preprocessor tools written in
    >Java? Hopefully it is able to use an abstract syntax tree so that I
    >can perform my own code transformations easily.


    see http://mindprod.com/jgloss/parser.html

    --

    Roedy Green Canadian Mind Products
    The Java Glossary
    http://mindprod.com
    Roedy Green, Apr 1, 2008
    #3
  4. I'm pretty sure javacc has a C parser in its repository.

    On Mon, 31 Mar 2008 23:26:45 -0700, student08 wrote:

    > Hi I'm currently looking for a C parser/preprocessor that's written in
    > Java (since I plan to be using the Prefuse visualisation toolkit) for
    > a student project.
    >
    > I looked at ANTLR but the gcc translation framework grammar that's
    > available on its website is fairly dated and I can't seem to find any
    > outside projects which use it and can verify its reliability. Also
    > it's only works with already preprocessed C and may not be able to
    > emit comments.
    >
    > Does anyone know any good C parser and preprocessor tools written in
    > Java? Hopefully it is able to use an abstract syntax tree so that I
    > can perform my own code transformations easily.
    Vlad Ciubotariu, Apr 1, 2008
    #4
  5. student08

    student08 Guest

    Hi first off thanks for the replies all.

    I've looked at JavaCC however its only has one rudimentary C grammar
    in its repository which can't handle preprocessed code. It seems to be
    the same for most of the others including Coco so I'm looking into
    Rats! in more detail and hopefully it will be the exception.

    However if anyone's worked with a Java parser which can handle C
    please feel free to mention it.

    Thanks
    student08, Apr 2, 2008
    #5
  6. student08

    EJP Guest

    You won't find a C preprocessor written with a parser-generation tool.
    It's not that kind of problem.
    EJP, Apr 2, 2008
    #6
  7. "EJP" <> wrote in message
    news:1pIIj.5183$...
    > You won't find a C preprocessor written with a parser-generation tool.
    > It's not that kind of problem.


    It is that kind of problem. Most C preprocessors are written
    using a well-divided lexer and parser (the latest GNU C
    preprocessor, for example). I'm sure you can find some that
    use parser-generators for the parse, though most are probably
    recursive-descent. You can write a C preprocessor as more
    of a lexer + state machine, but you would still want to use a
    parser for the constant integer expression evaluation.

    To the OP (the first post is missing from my news server, so
    I can't respond to it):

    What is the purpose of your code transformations? Will you
    perform transformations at the preprocessor-level, so that
    you need a preprocessor syntax tree? Is your goal to modify
    the original source code?
    Larry A Barowski, Apr 3, 2008
    #7
  8. student08

    student08 Guest

    On Apr 3, 11:12 pm, "Larry A Barowski"
    <ThisisLarrybarAtEngDotAuburnDotLearninginstitution> wrote:
    > "EJP" <> wrote in message
    >
    > news:1pIIj.5183$...
    >
    > > You won't find a C preprocessor written with a parser-generation tool.
    > > It's not that kind of problem.

    >
    > It is that kind of problem. Most C preprocessors are written
    > using a well-divided lexer and parser (the latest GNU C
    > preprocessor, for example). I'm sure you can find some that
    > use parser-generators for the parse, though most are probably
    > recursive-descent. You can write a C preprocessor as more
    > of a lexer + state machine, but you would still want to use a
    > parser for the constant integer expression evaluation.
    >
    > To the OP (the first post is missing from my news server, so
    > I can't respond to it):
    >
    > What is the purpose of your code transformations? Will you
    > perform transformations at the preprocessor-level, so that
    > you need a preprocessor syntax tree? Is your goal to modify
    > the original source code?


    Hi Larry thanks for the reply. My goal is to be able to highlight
    possible refactorings in the source code to the user and then if the
    user approves of the refactorings, to perform it by modifying the
    original source code.
    student08, Apr 8, 2008
    #8
  9. student08

    Yunzhong Guest

    Larry, which version of GNU C preprocessor did you check that used a
    parser generator?
    Yunzhong, Apr 8, 2008
    #9
  10. student08

    Roedy Green Guest

    On Tue, 1 Apr 2008 18:33:17 -0700 (PDT), student08
    <> wrote, quoted or indirectly quoted someone who
    said :

    >
    >However if anyone's worked with a Java parser which can handle C
    >please feel free to mention it.


    There are some preprocessors written in Java, but not C style. Since
    there are so many C-style preprocessors written in C, you'd think
    someone would want to revamp the aged syntax if they were to write a
    new one in Java.
    --

    Roedy Green Canadian Mind Products
    The Java Glossary
    http://mindprod.com
    Roedy Green, Apr 8, 2008
    #10
  11. student08

    Roedy Green Guest

    On Mon, 31 Mar 2008 23:26:45 -0700 (PDT), student08
    <> wrote, quoted or indirectly quoted someone who
    said :

    >Hi I'm currently looking for a C parser/preprocessor that's written in
    >Java (since I plan to be using the Prefuse visualisation toolkit) for
    >a student project.



    see http://mindprod.com/jgloss/preprocessor.html
    for a list of preprocessors associated with Java. Perhaps one might
    serve as a base.
    --

    Roedy Green Canadian Mind Products
    The Java Glossary
    http://mindprod.com
    Roedy Green, Apr 8, 2008
    #11
  12. On Tue, 08 Apr 2008 20:20:26 -0400, Lew wrote:
    > Larry A Barowski wrote:
    >> contains a one-pass C/C++ preprocessor+lexer with
    >> a constant integer expression parser generated by
    >> bison (the rest is a lexer and state machine), but it is
    >> not open source.

    >
    > Does that run afoul of the GPL?


    Conditions for using Bison:

    "The distribution terms for Bison-generated parsers permit using the
    parsers in nonfree programs."

    http://www.gnu.org/software/bison/manual/html_mono/bison.html#Conditions

    /gordon

    --
    Gordon Beaton, Apr 9, 2008
    #12
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bernd Oninger
    Replies:
    0
    Views:
    745
    Bernd Oninger
    Jun 9, 2004
  2. ZOCOR

    XML Parser VS HTML Parser

    ZOCOR, Oct 3, 2004, in forum: Java
    Replies:
    11
    Views:
    799
    Paul King
    Oct 5, 2004
  3. Bernd Oninger
    Replies:
    0
    Views:
    801
    Bernd Oninger
    Jun 9, 2004
  4. Cronus
    Replies:
    1
    Views:
    645
    Paul Mensonides
    Jul 15, 2004
  5. Peter Ammon

    Preprocessor harder to write than parser?

    Peter Ammon, Jul 14, 2007, in forum: C Programming
    Replies:
    1
    Views:
    526
    Jean-MArc Lienher
    Jul 14, 2007
Loading...

Share This Page