Beispiel #1
0
def main (single_run, use_ctl, use_dbg, text):
    exit = False
    db = MySQLdb.connect (host="localhost", user="******", passwd="qslbase", db="qslbase", charset="utf8")
    cursor = db.cursor ()
    result = ""
    sys.setdefaultencoding ("utf8")
    SyntaxAnalyzer (cursor)
    semantic_analyzer = SemanticAnalyzer (cursor)
    CodeProvider (cursor)
    CodeStack ()
    ErrorHelper (cursor)
    MemoryProvider ()
    ContextProvider ()
    TriggerProvider ()
    ConditionProvider ()
    DebuggerProvider (use_dbg)

    if single_run == False:
        stdin = os.open ("/tmp/qslime-std-in", os.O_RDONLY | os.O_NONBLOCK)
        stdout = os.open ("/tmp/qslime-std-out", os.O_WRONLY)
    if use_ctl == True:
        ctlout = os.open ("/tmp/qslime-ctl-out", os.O_WRONLY)
        ctlin = open ("/tmp/qslime-ctl-in", "r")
    if use_dbg == True:
        dbgout = os.open ("/tmp/qslime-dbg-out", os.O_WRONLY)
        dbgin = open ("/tmp/qslime-dbg-in", "r")
        DebuggerProvider.dbgin = dbgin
        DebuggerProvider.dbgout = dbgout
    if use_ctl == True:
        text = ctlin.readline ()
        if text != "":
            if SyntaxAnalyzer.analize (text):
                #PropositionTree.print_tree (SyntaxAnalyzer.proposition_tree)
                if semantic_analyzer.analize (SyntaxAnalyzer.proposition_tree, None):
                    #semantic_analyzer.proposition_tree.print_tree ()
                    result += semantic_analyzer.result
                    os.write (ctlout, 'OK.\n')
                else:
                    os.write (ctlout, semantic_analyzer.get_error_text () + '\n')
            else:
                os.write (ctlout, semantic_analyzer.get_error_text () + '\n')
    else:
        if text != "":
            #print text
            if DebuggerProvider.use == True:
                DebuggerProvider.reset ()
                DebuggerProvider.set_single_code_line (text)
                DebuggerProvider.build_debug_data ()
                DebuggerProvider.send_data ()
                DebuggerProvider.receive_data ()
            if SyntaxAnalyzer.analize (text):
                #SyntaxAnalyzer.proposition_tree.print_tree (SyntaxAnalyzer.proposition_tree)
                if semantic_analyzer.analize (SyntaxAnalyzer.proposition_tree, None):
                    #semantic_analyzer.proposition_tree.print_tree ()
                    result += semantic_analyzer.result
                else:
                    return semantic_analyzer.get_error_text ()
            else:
                return SyntaxAnalyzer.get_error_text ()

    while (exit != True):
        code_line = CodeStack.pop ()
        while (code_line != None):
            if code_line.text != "":
                #print code_line.text
                if DebuggerProvider.use == True:
                    if code_line.concept_id != 0 and code_line.id != 0:
                        DebuggerProvider.set_procedure_id (code_line.concept_id)
                        DebuggerProvider.set_line_id (code_line.id)
                    else:
                        DebuggerProvider.set_single_code_line (code_line.text)
                    DebuggerProvider.build_debug_data ()
                    DebuggerProvider.send_data ()
                    DebuggerProvider.receive_data ()
                analized = True
                if code_line.tree == None:
                    analized = SyntaxAnalyzer.analize (code_line.text)
                    tree = SyntaxAnalyzer.proposition_tree
                else:
                    tree = code_line.tree
                if analized:
                    #tree.print_tree (tree)
                    if semantic_analyzer.analize (tree, code_line):
                        #tree.print_tree (tree)
                        if code_line.tree != None:
                            if code_line.tree.is_totally_parsed == False:
                                code_line.tree = semantic_analyzer.proposition_tree
                                code_line.tree.is_totally_parsed = True
                        result += semantic_analyzer.result
                    else:
                        return semantic_analyzer.get_error_text ()
                else:
                    return SyntaxAnalyzer.get_error_text ()
                if CodeStack.is_empty () == True:
                    if CodeStack.inside_procedure == False:
                        if CodeProvider.is_priorities_assigned () == False:
                            CodeProvider.assign_priorities ()
                        TriggerProvider.dispatch_triggers ()
                        ConditionProvider.dispatch_conditions ()
                        CodeStack.sort ()
            else:
                if code_line.prev_line_id == -1 and code_line.concept_id != 0:
                    CodeProvider.execute_procedure (code_line.concept_id)
            code_line = CodeStack.pop ()

            if result != "" and single_run == False:
                #print result
                os.write (stdout, result)
                result = ""
                exit = True

        if single_run == True:
            return result

    os.close (stdin)
    os.close (stdout)
    os.close (ctlin)
    os.close (ctlout)
    os.close (dbgin)
    os.close (dbgout)