4

I am looking for something in Objective C that creates an AST out of objective c code that is modifiable. It would also be great if it also implements the visitor pattern for the AST. Basically looking for something like NRefactory is for c#.

Currently I am investigating CLang which is the only thing I have been able to google which looks close to what I want. If anyone with experience CLang can chime in, that would be great.

I am open to paid solutions as well.

Thanks!

Ali
  • 1,256
  • 3
  • 15
  • 31
  • 1
    After you modify the AST, what do you expect to have happen next? Generation of compiled code from the modified AST? Regeneration of valid source text? – Ira Baxter Oct 24 '11 at 17:33
  • Regeneration of valid source text. I don't think we require compiled code from modified AST. – Ali Oct 24 '11 at 18:10

2 Answers2

4

A week since your question, and zero responses.

I'd be surprised if you found an ObjectiveC tool that let you parse and transform ObjectiveC code. Such tools are really hard to build in general, and there's no obvious demand for one in ObjectiveC.

Clang seems like an option for processing ASTs, but it obviously isn't coded in ObjectiveC. I don't have any direct experience, but I understand Clang will parse ObjectiveC and build an AST. I suppose you can modify the AST, but I don't know if you can regenerate ObjectiveC code from that; I hear you can generate C++ code from a Clang AST for a parsed C++ program. (Clang is a tool that was really hard to build; look at its long history).

If Clang won't do, you might consider our DMS Software Reengineering Toolkit. DMS, given an explicit language description will parse, build ASTs for that language, let you inspect/modify the AST procedurally, and/or apply source-to-source transformations written using the surface syntax of the specified language (in your case, ObjectiveC), and regenerate valid source code in the language, including comments collected during parsing.

DMS has many language descriptions, including C, Java, C++ (including C++11), COBOL, PHP, etc. There isn't presently a description for ObjectiveC, but DMS is designed to make it easy to provide such language description as might be obvious from what we already have. Compared to building the parsing/transformation/prettyprinting machinery (which was all really hard to build!), defining a language front end is a pretty small task.

EDIT June 8, 2012: (9 months after question, no other responses) DMS now has an ObjectiveC front end. You can see a DMS-generated parse tree for a small ObjectiveC code here: https://stackoverflow.com/a/10749970/120163 Yes, DMS can regenerate valid ObjectiveC source code from such (modified) trees.

Community
  • 1
  • 1
Ira Baxter
  • 93,541
  • 22
  • 172
  • 341