2

I have a domain specific language and I want to do a static analysis on that language in order to great a graph. Appreciate if somebody could recommend a action plan on doing this.

Domain Language

{
   run_and_branch(ULSDCompHash)
   then
   {
      run(DownComponent_Reset);
      run(DownComponent_Reset2);

   }
   else
   {
      run(ULSD_EndOfTest);
   }
   run(ULSD_EndOfTest2);


}, closed,"EMCSETUP",""

Details on the Language

  • run does not care if the condition pass or fail
  • run_and_branch is like if - else, if pass or fail kind of thing
  • The value within the () is the name of the node

Expected Output (If Run a DFS on the Graph)

 ULSDCompHash -> DownComponent_Reset -> DownComponent_Reset2 -> ULSD_EndOfTest2
 ULSDCompHash -> ULSD_EndOfTest -> ULSD_EndOfTest2
tabiul
  • 607
  • 3
  • 8
  • 17
  • What kind of graph do you want to create exactly? A control flow graph? And is it an artifact of plain-text representation or should there really be separate nodes for things that occur in two code paths? –  Apr 01 '12 at 07:51
  • 1
    A control flow graph I feel is appropriate so that I can do DFS traversal to get all possible paths. The graph should mimic the plain text representation. So in my example there will be a single node ULSDCompHash that has a one out edge to DownComponent_Reset and another out edge to ULSD_EndofTest – tabiul Apr 01 '12 at 11:35
  • After doing more googling around, the first step is to create the AST Tree for the source code and then transform that into Control Flow Graph. I am not able to find any good source like step by step explanation on how to transform the AST to CFG – tabiul Apr 01 '12 at 12:46

1 Answers1

1

Most compiler books contain pretty detailed descriptions of how to produce control flow graphs.

I provided an SO answer as to how to crawl an AST to produce a CFG for a Java program, but the answer is rather generic.

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