5

I would like to create an Java source code parsing functionality in C++. The purpose of this application is to generate a syntax tree into the internal data structure so that I am able to walk the data tree structure and analyse it on my own.

Which tools could help me to achive my goal?

7
  • 1
    There are many tools for this. Google for parser generators. Commented Dec 12, 2011 at 12:46
  • 2
    The obvious question would be why do you want to do this? You may find it simpler and easier to run javac and parse the byte code generated instead. Commented Dec 12, 2011 at 12:47
  • Doing things like these helps tremendously in understanding the basic principles of the material you're working on. E.G. I once wrote a full SGML parser, and that helped me answer a lot of questions that I didn't even knew I had. Commented Dec 12, 2011 at 12:55
  • @MarceloCantos So, at first I need to pick up a parser generator? OK. I found Bison and YACC softwares. How about one of these? Commented Dec 12, 2011 at 13:04
  • 1
    @PeterLawrey: At the moment I am doing some preliminary research about how could I break the language structure into peaces. This way I am able to understand the Java language better - I think :-). Commented Dec 12, 2011 at 13:08

3 Answers 3

3

Perhaps ANTLR could help you, but understanding a Java program requires to load the relevant classes referenced in that program.

Sign up to request clarification or add additional context in comments.

2 Comments

Moreover, they may be existing grammars for C++.
@Agemen: I found out that ANTLR is able to generate C++ source code but I have determined that I am not going to use any language that is using virtual machine. :-)
1

You could use yacc with this grammar.

Comments

1

You can also try;

http://www.ssw.uni-linz.ac.at/Research/Projects/Coco/

It has different ports like C#, Java, C++, F#, VB.Net, Oberon etc. and it has a nice language scanner & parser for different langauges. So, you can use it for parsing java from c++.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.