views:

109

answers:

1

How can I do modeling in reverse by parsing a C program and turning it in to a circuit diagram to be displayed.

Example

alt text

alt text

Except this is psedocode.

A: 

At a first guess I would say you need to construct a C compiler from scratch (or co-opt one) and inspect the parse tree looking for constructs that you can represent with your list of simple symbols. Once you have done that you need a rendering engine to take the list of detected constructs and lay them out in a pretty picture.

Some random observations:

  1. There are many C concepts that can't be rendered in a simplistic manner (ie pointers)

  2. Making your pic look pretty will be a bitch

  3. Doxygen would be a good place to look for ideas (the do a nice function call structure graph)

  4. Going off on a tangent you might like to look at IEC 61131-3 programming languages for PLCs. These are graphically laid out languages that provide 5 different ways of describing program control and focus heavily on representations of logic

Peter M