Пример #1
0
    def __code_pre_context_state_machine(self):
        LanguageDB = self.language_db

        if len(self.pre_context_sm_list) == 0: return []

        assert len(self.pre_context_sm.get_orphaned_state_index_list()) == 0

        txt = []
        if Setup.comment_state_machine_f:
            LanguageDB.ML_COMMENT(txt,
                                  "BEGIN: PRE-CONTEXT STATE MACHINE\n"             + \
                                  self.pre_context_sm.get_string(NormalizeF=False) + \
                                  "END: PRE-CONTEXT STATE MACHINE")
            txt.append(
                "\n"
            )  # For safety: New content may have to start in a newline, e.g. "#ifdef ..."

        analyzer = analyzer_generator.do(self.pre_context_sm,
                                         E_EngineTypes.BACKWARD_PRE_CONTEXT)
        msg = state_machine_coder.do(analyzer)
        txt.extend(msg)

        txt.append("\n%s" %
                   LanguageDB.LABEL(E_StateIndices.END_OF_PRE_CONTEXT_CHECK))
        # -- set the input stream back to the real current position.
        #    during backward lexing the analyzer went backwards, so it needs to be reset.
        txt.append("    %s\n" % LanguageDB.INPUT_P_TO_LEXEME_START())

        for sm_id in self.pre_context_sm_id_list:
            variable_db.require("pre_context_%i_fulfilled_f", Index=sm_id)

        return txt
Пример #2
0
    def __code_pre_context_state_machine(self):
        LanguageDB = self.language_db

        if len(self.pre_context_sm_list) == 0: return []

        assert len(self.pre_context_sm.get_orphaned_state_index_list()) == 0

        txt = []
        if Setup.comment_state_machine_f:
            LanguageDB.ML_COMMENT(txt, 
                                  "BEGIN: PRE-CONTEXT STATE MACHINE\n"             + \
                                  self.pre_context_sm.get_string(NormalizeF=False) + \
                                  "END: PRE-CONTEXT STATE MACHINE") 
            txt.append("\n") # For safety: New content may have to start in a newline, e.g. "#ifdef ..."

        analyzer = analyzer_generator.do(self.pre_context_sm, E_EngineTypes.BACKWARD_PRE_CONTEXT)
        msg      = state_machine_coder.do(analyzer)
        txt.extend(msg)

        txt.append("\n%s" % LanguageDB.LABEL(E_StateIndices.END_OF_PRE_CONTEXT_CHECK))
        # -- set the input stream back to the real current position.
        #    during backward lexing the analyzer went backwards, so it needs to be reset.
        txt.append("    %s\n" % LanguageDB.INPUT_P_TO_LEXEME_START())

        for sm_id in self.pre_context_sm_id_list:
            variable_db.require("pre_context_%i_fulfilled_f", Index = sm_id)

        return txt
Пример #3
0
    def __code_main_state_machine(self):
        assert len(self.sm.get_orphaned_state_index_list()) == 0

        LanguageDB = self.language_db 
        txt        = []

        # -- [optional] comment state machine transitions 
        if Setup.comment_state_machine_f:
            LanguageDB.ML_COMMENT(txt, 
                                  "BEGIN: STATE MACHINE\n"             + \
                                  self.sm.get_string(NormalizeF=False) + \
                                  "END: STATE MACHINE") 
            txt.append("\n") # For safety: New content may have to start in a newline, e.g. "#ifdef ..."

        # -- implement the state machine itself
        analyzer           = analyzer_generator.do(self.sm, E_EngineTypes.FORWARD)
        state_machine_code = state_machine_coder.do(analyzer)
        txt.extend(state_machine_code)

        lexeme_null_object_name = "QUEX_NAME(LexemeNullObject)"
        if Setup.external_lexeme_null_object != "":
            lexeme_null_object_name = Setup.external_lexeme_null_object

        # -- terminal states: execution of pattern actions  
        terminal_code = LanguageDB["$terminal-code"](self.state_machine_name,
                                                     self.action_db, 
                                                     self.on_failure_action, 
                                                     self.on_end_of_stream_action, 
                                                     self.pre_context_sm_id_list,
                                                     self.language_db, 
                                                     variable_db,
                                                     self.on_after_match, 
                                                     lexeme_null_object_name) 
        
        txt.extend(terminal_code)

        N = len(set(analyzer.position_register_map.values()))
        if len(analyzer.position_register_map) == 0:
            variable_db.require("position",          Initial = "(void*)0x0", Type = "void*")
            variable_db.require("PositionRegisterN", Initial = "(size_t)%i" % N)
        else:
            variable_db.require_array("position", ElementN = N,
                                      Initial  = "{ " + ("0, " * (N - 1) + "0") + "}")
            variable_db.require("PositionRegisterN", Initial = "(size_t)%i" % N)
    
        if analyzer.last_acceptance_variable_required():
            variable_db.require("last_acceptance")

        # -- reload definition (forward, backward, init state reload)
        code = LanguageDB.RELOAD()
        txt.extend(code)

        return txt
Пример #4
0
    def __code_main_state_machine(self):
        assert len(self.sm.get_orphaned_state_index_list()) == 0

        LanguageDB = self.language_db
        txt = []

        # -- [optional] comment state machine transitions
        if Setup.comment_state_machine_f:
            LanguageDB.ML_COMMENT(txt,
                                  "BEGIN: STATE MACHINE\n"             + \
                                  self.sm.get_string(NormalizeF=False) + \
                                  "END: STATE MACHINE")
            txt.append(
                "\n"
            )  # For safety: New content may have to start in a newline, e.g. "#ifdef ..."

        # -- implement the state machine itself
        analyzer = analyzer_generator.do(self.sm, E_EngineTypes.FORWARD)
        state_machine_code = state_machine_coder.do(analyzer)
        txt.extend(state_machine_code)

        lexeme_null_object_name = "QUEX_NAME(LexemeNullObject)"
        if Setup.external_lexeme_null_object != "":
            lexeme_null_object_name = Setup.external_lexeme_null_object

        # -- terminal states: execution of pattern actions
        terminal_code = LanguageDB["$terminal-code"](
            self.state_machine_name, self.action_db, self.on_failure_action,
            self.on_end_of_stream_action, self.pre_context_sm_id_list,
            self.language_db, variable_db, self.on_after_match,
            lexeme_null_object_name)

        txt.extend(terminal_code)

        N = len(set(analyzer.position_register_map.values()))
        if len(analyzer.position_register_map) == 0:
            variable_db.require("position", Initial="(void*)0x0", Type="void*")
            variable_db.require("PositionRegisterN", Initial="(size_t)%i" % N)
        else:
            variable_db.require_array("position",
                                      ElementN=N,
                                      Initial="{ " + ("0, " * (N - 1) + "0") +
                                      "}")
            variable_db.require("PositionRegisterN", Initial="(size_t)%i" % N)

        if analyzer.last_acceptance_variable_required():
            variable_db.require("last_acceptance")

        # -- reload definition (forward, backward, init state reload)
        code = LanguageDB.RELOAD()
        txt.extend(code)

        return txt
Пример #5
0
    def __code_backward_input_position_detection_core(self, SM):
        assert len(SM.get_orphaned_state_index_list()) == 0
        
        txt = []
        if Setup.comment_state_machine_f: 
            Setup.language_db.ML_COMMENT(txt, 
                                         "BEGIN: BACKWARD DETECTOR STATE MACHINE\n" + \
                                         SM.get_string(NormalizeF=False)            + \
                                         "\nEND: BACKWARD DETECTOR STATE MACHINE")
            txt.append("\n")

        analyzer      = analyzer_generator.do(SM, E_EngineTypes.BACKWARD_INPUT_POSITION)
        function_body = state_machine_coder.do(analyzer)

        txt.extend(function_body)

        return txt
Пример #6
0
    def __code_backward_input_position_detection_core(self, SM):
        assert len(SM.get_orphaned_state_index_list()) == 0

        txt = []
        if Setup.comment_state_machine_f:
            Setup.language_db.ML_COMMENT(txt,
                                         "BEGIN: BACKWARD DETECTOR STATE MACHINE\n" + \
                                         SM.get_string(NormalizeF=False)            + \
                                         "\nEND: BACKWARD DETECTOR STATE MACHINE")
            txt.append("\n")

        analyzer = analyzer_generator.do(SM,
                                         E_EngineTypes.BACKWARD_INPUT_POSITION)
        function_body = state_machine_coder.do(analyzer)

        txt.extend(function_body)

        return txt
Пример #7
0
def do_analyzer(analyzer): 
    state_machine_code = state_machine_coder.do(analyzer)
    Lng.REPLACE_INDENT(state_machine_code)
    # Variable to store the current input
    variable_db.require("input") 
    return state_machine_code
Пример #8
0
def do_analyzer(analyzer):
    state_machine_code = state_machine_coder.do(analyzer)
    Lng.REPLACE_INDENT(state_machine_code)
    # Variable to store the current input
    variable_db.require("input")
    return state_machine_code