forked from DingJianhao/auto_flowchart
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtranslate.py
76 lines (75 loc) · 2.43 KB
/
translate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
from collections import deque
import analyze as az
import operator
G=az.get_graph("sample2.cpp")
queue = deque()
queue.append(0)
visited=[]
vis={}
cnt=0
while len(queue)!=0:
pos = queue[0]
queue.popleft()
if pos in visited:
continue
if pos==0:
cnt=0
else:
cnt=cnt+1
vis[pos]=cnt
visited.append(pos)
if G[pos].yes!=-1:
queue.append(G[pos].yes)
if G[pos].no!=-1:
queue.append(G[pos].no)
print(vis)
tail=vis[1]
for i in vis:
if vis[i]>tail:
vis[i]=vis[i]-1
vis[1]=len(vis)
print(vis)
v=sorted(vis.items(),key = operator.itemgetter(1))
print(v)
print("STEP%-2d: 开始" % 0)
for (pos,i) in v:
print("STEP%-2d: " % (i), end="")
if G[pos].type == 2:
if G[pos].yes != -1 and G[pos].no != -1:
print("Beurteilung <= [Handan]%s Wenn die Bedingung wahr ist, springen Sie zu SCHRITT%d; Andernfalls springen Sie zu SCHRITT%d" % (G[pos].content, vis[G[pos].yes], vis[G[pos].no]))
if G[pos].yes != -1 and G[pos].no == -1:
print("Beurteilung <= [Handan]%s Wenn die Bedingung wahr ist, springen Sie zu SCHRITT%d" % (G[pos].content, vis[G[pos].yes]))
if G[pos].yes == -1 and G[pos].no != -1:
print("Beurteilung <= [Handan]%s Wenn die Bedingung falsch ist, springen Sie zu SCHRITT%d" % (G[pos].content, vis[G[pos].no]))
else:
print(G[pos].content)
'''
queue = deque()
queue.append(0)
visited=[]
cnt=0
while len(queue)!=0:
pos = queue[0]
queue.popleft()
if pos in visited:
continue
if pos==0:
cnt=0
print("STEP%-2d: 开始" % (cnt))
else:
cnt=cnt+1
print("STEP%-2d: "%(cnt),end="")
if G[pos].type==2:
if G[pos].yes!=-1 and G[pos].no!=-1:
print("判断%s 如果条件为真,跳转到STEP%d;否则,跳转到STEP%d" % (G[pos].content,vis[G[pos].yes],vis[G[pos].no]))
if G[pos].yes!=-1 and G[pos].no==-1:
print("判断%s 如果条件为真,跳转到STEP%d" % (G[pos].content,vis[G[pos].yes]))
if G[pos].yes==-1 and G[pos].no!=-1:
print("判断%s 如果条件为假,跳转到STEP%d" % (G[pos].content,vis[G[pos].no]))
else:
print(G[pos].content)
visited.append(pos)
if G[pos].yes!=-1:
queue.append(G[pos].yes)
if G[pos].no!=-1:
queue.append(G[pos].no)'''