Java C Parser/Preprocessor

S

student08

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.
 
S

student08

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
 
E

EJP

You won't find a C preprocessor written with a parser-generation tool.
It's not that kind of problem.
 
L

Larry A Barowski

EJP said:
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?
 
S

student08

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.
 
Y

Yunzhong

Larry, which version of GNU C preprocessor did you check that used a
parser generator?
 
R

Roedy Green

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,772
Messages
2,569,591
Members
45,102
Latest member
GregoryGri
Top