I’m making a programming language named ‘procol’. It has basic syntax, much like a regular old programming language. Since the output can only display text, I decided to make it so that when a variable is set to inco(”), it will make a new window, asking with the prompt, and with a text-bar. I tried making the answer submitted on the text bar the variables value but it won’t work. For extra information, I’m using the tkinter module. Heres the code(I just started on it so there’s lack of currently usable functions):
import tkinter as tk
variables = {}
def inco(prompt):
root = tk.Tk()
def on_submit(var_name):
user_input = entry.get()
variables[var_name] = user_input
root.destroy()
label = tk.Label(root, text=prompt)
label.pack()
entry = tk.Entry(root)
entry.pack()
submit_button = tk.Button(root, text="Submit", command=lambda: on_submit(prompt))
submit_button.pack()
root.mainloop()
def run_program():
code = code_input.get('1.0', 'end-1c')
output = ''
lines = code.split('n')
for line in lines:
line = line.strip()
if not line:
continue
if 'inco(' in line:
prompt = line.split("inco(")[1].split(")")[0]
inco(prompt)
elif '=' in line:
data_type, rest = line.split(maxsplit=1)
variable_name, value = rest.split('=', 1)
variable_name = variable_name.strip()
value = value.strip()
if 'inco(' in value:
prompt = value.split("inco(")[1].split(")")[0]
inco(prompt)
else:
if data_type == 'int':
variables[variable_name] = int(value)
elif data_type == 'dbl':
variables[variable_name] = float(value)
elif data_type == 'str':
variables[variable_name] = value
elif 'disco(' in line:
expression = line.split("disco(")[1].split(")")[0]
result = eval(expression, {}, variables)
output += str(result) + 'n'
output_text.set(output)
root = tk.Tk()
root.title("Procol Compiler")
code_input = tk.Text(root, wrap=tk.WORD)
code_input.pack(fill=tk.BOTH, expand=True)
output_text = tk.StringVar()
output_label = tk.Label(root, textvariable=output_text, wraplength=400)
output_label.pack()
run_button = tk.Button(root, text="Run", command=run_program)
run_button.pack(side=tk.LEFT)
root.mainloop()