1

I searched plenty of sources but havent found anything yet. I'm trying to create an AST (in Java) for a input file written in C. I found ANTLR and it works with the "official" C-Grammar from the ANTLR examples. Nevertheless, I read about editing grammar for the syntax-tree with e.g. "^" to mark roots etc.

When I set the output at the C.g to output=AST an empty graph is printed (some dot gibberish). Also I can't find any of that mentioned tree symbols in the grammar.

So I need to asume, that grammar doesn't support AST-generation.

Is there any working C grammar that has syntax for a AST in it? I need to find a solution in a proper time, and I wanted to check all available ressources bevor starting to edit the given grammar (what I guess will be an awful lot of work).

Thanks for you time,

Simon

smoes
  • 591
  • 2
  • 17
  • 2
    A reliable C parser is difficult to produce. The language has lots of tricky details defined by just the standard, and then you discover that the compilers do a lot of different surprising things. You also need to worry about how to handle preprocessing. Finally, you didn't say what you wanted to do with your C parse... usually you need a lot more than just parsing. See my essay on "Life After Parsing" http://www.semanticdesigns.com/Products/DMS/LifeAfterParsing.html – Ira Baxter Nov 09 '12 at 15:08
  • Till now I do the preprocessing with gcc (set of flags).The AST is needed to create a CDFG for a specific architecture we're developing. – smoes Nov 09 '12 at 18:56
  • Might want to look at Clang/LLVM. –  Nov 09 '12 at 19:59
  • @smoes: So you are really looking for a C front end that produces control and data flows? – Ira Baxter Nov 10 '12 at 07:57
  • C -> (not necessarily) Java-Parser -> AST in anyformat. The plan is to transform this AST into the CDFG of our needs. – smoes Nov 10 '12 at 12:53
  • Why aren't you investigating solutions that already provide CDFGs, rather than (apparantly) insisting on building one of your one from an AST you don't have ("what I guess will be awful lot of work") [you got that right]? – Ira Baxter Nov 10 '12 at 15:21
  • Good question. There are several reasons. We want to have a java source code to fit in into the rest of our code. But thats not mandatory. The main thing is, that it is hard to find a well documented open source code. We're doing research we cant work with a black box where optimization is done. We need to know exactly what happens inside. An that is even harder to find / more time consuming then the other approach I thought. Apparently I was wrong. – smoes Nov 12 '12 at 08:48
  • "When optimization is done"? You appear to want flow analysis, as a precursor to doing optimization. If you have flow analysis (black box or not), "knowing" what it does is mostly a matter of inspecting the result for some examples. (Of course, you might ask the authors of the box). Ultimately having the framework in your hands with some unclarity about what it does, is likely to do you a lot more good that not having a framework and trying to do it yourself, at least if your objective is get on with your task. Do you insist on open source? Or just that you can inspect/change it? – Ira Baxter Nov 17 '12 at 18:58

0 Answers0