中间代码生成-四元式

代码:

import tkinter as tk

root = tk.Tk()
root.geometry("800x600+50+50")
root.title("中间代码生成")

label2 = tk.Label(root, text = "请输入赋值语句:")
label2.place(x=10,y=10)

label3 = tk.Label(root, text = "四元式序列:")
label3.place(x=400,y=10)


text1 = tk.Text(root,width=35,height=15,bg="#e8e8e8",font="Consolas")
text1.place(x=10,y=50)

text2 = tk.Text(root,width=35,height=15,bg="#e8e8e8",font="Consolas")
text2.place(x=400,y=50)

def result():
	text2.delete(1.0,"end")
	string = text1.get(1.0,"end")
	list = []
	i=0
	t=1
	while i < len(string):
		var = string[i:i+5]
		var1 = 't'+str(t)+var[1:]
		var2 = var[0:2]+'t'+str(t)+'+-'
		list.append(var1)
		list.append(var2)
		t=t+1
		i=i+6	
	i = 0
	tuple = ()
	while i < len(list) :
		if i%2 == 0:
			tuple = (list[i][4],list[i][3],list[i][5],list[i][0:2])
		else:
			tuple = (list[i][1],list[i][2:4],list[i][5],list[i][0])
		text2.insert("insert",str(tuple)+"\n")
		i = i+1


button1 = tk.Button(root, text = "生成",bg="#e8e8e8",width=5,height=1,padx=5,command=result)
button1.place(x=140,y=10)

root.mainloop()

图片:

中间代码生成-四元式_第1张图片

你可能感兴趣的:(Language)