Tools for Automated Source Code Editing

Posted by Steve on Stack Overflow See other posts from Stack Overflow or by Steve
Published on 2011-01-06T03:38:02Z Indexed on 2011/01/06 11:54 UTC
Read the original article Hit count: 146

Filed under:
|
|
|

I'm working on a research project to automatically modify code to include advanced mathematical concepts (like adding random effects into a loop or encapsulating an existing function with a new function that adds in a more advanced physical model).

My question to the community is: are there are any good tools for manipulating source code directly? I want to do things like

  • Swap out functions
  • Add variable declarations wherever they are required
  • Determine if a function is multiplied by anything
  • Determine what functions are called on a line of code
  • See what parameters are passed to a function and replace them with alternatives
  • Introduce new function calls on certain lines of code
  • Wherever possible just leaving the rest of the code untouched and write out the results

I never want to actually compile the code I only want to understand what symbols are used, replace and add in a syntactically correct way, and be able to declare variables at the right position.

I've been using a minimal flex/bison approach with some success but I do not feel the it is robust. I hate to take on writing a full language parser just to add some new info to the end of a line or the top of a function. It seems like this is almost what is going to be required but it also seems like there should be some tools out there to do these types of manipulations already.

The code to be changed is in a variety of languages, but I'm particularly interested in FORTRAN.

Any thoughts?

© Stack Overflow or respective owner

Related posts about flex

Related posts about parsing