Example #1
0
def run_in_CLI(string):
    root = parser.parse(string)
    # v = Viz(root)
    # v.png()
    c = Codegen(root)
    c.codegen()
    c.crun(root.children[0].children[1].name, [])
Example #2
0
def printass():
    try:
        dst.config(state=tk.NORMAL)
        dst.delete(0.0, tk.END)
        astroot = parser.parse(src.get(0.0, tk.END))
        ircodegen = Codegen(astroot)
        dst.insert(tk.END, ircodegen.codegen())
        dst.config(state=tk.DISABLED)

    except CompilerError.SplTypeError as error:
        messagebox.showerror("Type Error", error.args[0])
    except CompilerError.MultiDefinedError as error:
        messagebox.showerror("Conflict declaration Error", error.args[0])
    except CompilerError.NotDefinedError as error:
        messagebox.showerror("Implicit declaration Error", error.args[0])
    except CompilerError.OpError as error:
        messagebox.showerror("Operation Error", error.args[0])
    except CompilerError.ExpressionError as error:
        messagebox.showerror("Expression Error", error.args[0])
    except CompilerError.ParseError as error:
        messagebox.showerror("Expression Error", error.args[0])
    except CompilerError.LexError as error:
        messagebox.showerror("Expression Error", error.args[0])
Example #3
0
    def terminal_run(cmmd):
        # terminal_text.insert(tk.END, cmmd + "\n")
        if (cmmd == ""):
            return
        if (cmmd == "clear"):
            terminal_text.delete(0.0, tk.END)
            terminal_text.insert(tk.END, "MySPL Compiler > ")
            return
        if (cmmd == "exit"):
            terminal.destroy()
            terminal_text.insert(tk.END, "MySPL Compiler > ")
            return
        if (cmmd == "translate"):
            printass()
            terminal_text.insert(tk.END, "MySPL Compiler > ")
            return
        if (cmmd == "open"):
            openfile()
            terminal_text.insert(tk.END, "MySPL Compiler > ")
            return
        if (cmmd == "tree"):
            showtree()
            terminal_text.insert(tk.END, "MySPL Compiler > ")
            return
        if (cmmd == "ir"):
            ir = showir()
            terminal_text.insert(tk.END, ir + '\n' + "MySPL Compiler > ")
            return
        if (cmmd == "main"):
            res = test_print()
            terminal_text.insert(
                tk.END, "During RUNING... \n" + res + "MySPL Compiler > ")
            return
        if (cmmd == "info"):
            information =   '2019 SPRING&SUMMER  Compiler Principle Project:    Mini SPL  Compiler \n' \
                            'Surpport: \n' \
                         '>> Pascal Language, generate assembly code \n' \
                            '>> Visual syntax tree \n' \
                            '>> Interactive command line Terminal \n' \
                            '>> Load code from file \n' \
                            '>> Executable function \n' \
                            'Author: Xu Jinyan/Xiang Liming/Peng Dishuo © ZJU'

            terminal_text.insert(tk.END, information + " \nMySPL Compiler > ")
            return
        func_list = cmmd.split("(")
        func_name = func_list[0]
        #terminal_text.insert(tk.END, func_name + " ")
        arg_string = func_list[1].split(")")
        arg_list = arg_string[0].split(",")
        arg_list_done = []
        for i in arg_list:
            for j in i.split(" "):
                if (j != ""):
                    arg_list_done += [j]

        func_arg = []
        for arg in arg_list_done:
            func_arg += [int(arg)]
            #terminal_text.insert(tk.END, arg + " ")
        astroot = parser.parse(src.get(0.0, tk.END))
        ircodegen = Codegen(astroot)
        ircodegen.codegen()

        result = ircodegen.crun(func_name, func_arg)
        terminal_text.insert(
            tk.END,
            "Result of " + cmmd + ": " + str(result) + " \nMySPL Compiler > ")
Example #4
0
def showir():
    astroot = parser.parse(src.get(0.0, tk.END))
    code = Codegen(astroot)
    result = code.irshow()
    # result = str(result).replace('\\', '\\\\')
    return str(result)
Example #5
0
def showtree():
    astroot = parser.parse(src.get(0.0, tk.END))
    Viz(astroot).png()