以编程方式创建流程图的逻辑 [英] Logic to creae a flow chart progammatically

查看:125
本文介绍了以编程方式创建流程图的逻辑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我知道这是一个模糊的问题,但是我似乎在这里陷入逻辑……我想创建输入程序的流程图.我从两天开始就在考虑这个问题,无法获得最佳的一般方法...所以我拼命地看着你们,在这里帮我....也许是我缺少了一些小东西....
我有一个xml文件,其中包含有关给定Java程序的信息,如下所示:

OK, I know it''s a vague question, but I seem to be stuck with logic here...I want to create flow charts of the input programs. I hav been thinking about it since two days and can''t get a best general approach...So i look desperately at you guyz to help me here....may be there is something small I am missing....
I have an xml file which contains the info about the given java program and looks like this:

   <method modifier="publicstatic" type="void" name="main">
<FormalParameter modifier="" type="String[]" var_name="args" />
<throw>NullPointerException</throw>
<throw>IndexOutofBoundException</throw>
<field modifier="" type="int" name=" x,y,z" />
<field modifier="" type="int" name=" sum[] " />
<if> <condition><![CDATA[(x==0)</condition>
<statement> <![CDATA[System.out.Println("I am in true")</statement>
<if> <condition><![CDATA[(y==2)</condition>
<statement> <![CDATA[System.out.Println("I am in true of y==2")</statement>
</if>
<statement> <![CDATA[System.out.prnitln("I am in true again")</statement>
</if>
<else>
<if> <condition><![CDATA[(x==2)</condition>
<statement> <![CDATA[System.out.println("I am in x==2 true")</statement>
</if>
<else>
<statement> <![CDATA[System.out.println("I am in else 2")</statement>
</else>
</else>
<statement> <![CDATA[c=b+d</statement>
<statement> <![CDATA[a=b+c</statement>
</method>


现在,这是生成的xml文件的一部分....参见代码段:




Now this is a part of the xml file generated....fir the code snippet:



public static void main(String[] args) throws NullPointerException,IndexOutofBoundException {
   int x,y,z;
    int sum[]={1,2,3,4};
   if(x==0)
      {
        System.out.Println("I am in true");
        if(y==2)
          {
              System.out.Println("I am in true of y==2");
          }
        System.out.prnitln("I am in true again");
      }
   else if(x==2)
    {
       System.out.println("I am in x==2 true");
     }
     else
   {
      System.out.println("I am in else 2");
   }

     c=b+d;
     a=b+c;

    }



现在我的做法是...
我有一个可以读取xml文件的类阅读器,还有一个可以处理绘图的createFLowChart类.
我开始遍历方法节点...如果找到一条语句..我调用一个函数FundStatement,该函数绘制一个矩形框并将其与prv节点连接...对If-else构造执行此操作,而无需添加很多状态布尔变量.....
那么任何人都可以在这方面指导我吗? 现在问题是带有if-else构造的...我无法找到一种简单的遍历if -else树并正确地在节点之间进行边缘连接的遍历方法,而没有添加一些变量来包含状态信息,即if已启动或已启动等...



Now my way of doing it is ...
I have a class reader which reades the xml file and one class createFLowChart which takes care of drawing
I start traversing the method node...if I find a statement..I call a function FundStatement which draws a retangular box and connects it with prv node...doing this for If-else constructs without adding a lot of state boolean variables.....
So can any one guide me in this????.......
Now the prob is with if-else constructs...I can not find a simple way of traversig through the if -else trees and correctly make the edge connections among the nodes without adding a number of variables to contain the state info i.e an if has started or else started etc...

推荐答案

如果不是OO,请不要使用流程图.从OO角度来看,交互或顺序图会更好,请参见 [
Don''t use a flowchart if it''s OO. An interaction or sequence diagram would be better from an OO perspective, see this[^]


这篇关于以编程方式创建流程图的逻辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆