Exemple #1
0
    def analyzer_function_get(self, RequiredLocalVariablesDB):
        routed_address_set = set([])
        function_body = []

        # (*) Core State Machine
        #     All pattern detectors combined in single forward analyzer
        dsm = StateMachineDecorator(self.sm,
                                    self.state_machine_name,
                                    self.post_contexted_sm_id_list,
                                    BackwardLexingF=False,
                                    BackwardInputPositionDetectionF=False)

        variable_db.init(RequiredLocalVariablesDB)
        init_address_handling(dsm.get_direct_transition_to_terminal_db())

        # (*) Pre Context State Machine
        #     All pre-context combined in single backward analyzer.
        if self.pre_context_sm_list != []:
            code = self.__backward_analyzer()
            function_body.extend(code)

        # -- now, consider core state machine
        code = self.__forward_analyzer(dsm)
        function_body.extend(code)

        # At this point in time, the function body is completely defined
        routed_address_set = get_address_set_subject_to_routing()

        if len(routed_address_set) != 0 or is_label_referenced(
                "$state-router"):
            routed_state_info_list = state_router.get_info(
                routed_address_set, dsm)
            function_body.append(state_router.do(routed_state_info_list))
            variable_db.require("target_state_index",
                                Condition_ComputedGoto=False)

        if is_label_referenced("$reload-FORWARD") or is_label_referenced(
                "$reload-BACKWARD"):
            variable_db.require("target_state_else_index")
            variable_db.require("target_state_index")

        # Following function refers to the global 'variable_db'
        variable_definitions = self.language_db["$variable-definitions"](
            self.post_contexted_sm_id_list, self.pre_context_sm_id_list,
            self.language_db)

        # (*) Pack Pre-Context and Core State Machine into a single function
        analyzer_function = self.language_db["$analyzer-func"](
            self.state_machine_name,
            self.analyzer_state_class_name,
            self.stand_alone_analyzer_f,
            variable_definitions,
            function_body,
            self.mode_name_list,
            LanguageDB=self.language_db)

        return get_plain_strings(analyzer_function)
Exemple #2
0
    def backward_detector_function_get(self, sm):
        assert sm.get_orphaned_state_index_list() == []

        dsm = StateMachineDecorator(sm, 
                                    "BACKWARD_DETECTOR_" + repr(sm.get_id()),
                                    PostContextSM_ID_List           = [], 
                                    BackwardLexingF                 = True, 
                                    BackwardInputPositionDetectionF = True)

        variable_db.init()
        init_address_handling(dsm.get_direct_transition_to_terminal_db())

        function_body = state_machine_coder.do(dsm)

        comment = []
        if Setup.comment_state_machine_transitions_f: 
            comment = Setup.language_db["$ml-comment"]("BEGIN: BACKWARD DETECTOR STATE MACHINE\n" + \
                                                       sm.get_string(NormalizeF=False)            + \
                                                       "\nEND: BACKWARD DETECTOR STATE MACHINE")
            comment.append("\n")


        # -- input position detectors simply the next 'catch' and return
        terminal = []
        terminal.append("\n")
        terminal.append("    __quex_assert_no_passage();\n")
        terminal.append(get_label("$terminal-general-bw") + ":\n")
        terminal.append("    " + self.language_db["$input/seek_position"]("end_of_core_pattern_position") + "\n")
        terminal.append("    " + self.language_db["$input/increment"] + "\n")
        terminal.append("    return;\n")

        routed_address_set = get_address_set_subject_to_routing()

        state_router_txt = ""
        if len(routed_address_set) != 0:
            routed_state_info_list = state_router.get_info(routed_address_set, dsm)
            state_router_txt       = state_router.do(routed_state_info_list)
            variable_db.require("target_state_index", Condition_ComputedGoto=False)

        variable_db.require("input")
        variable_db.require("end_of_core_pattern_position")

        local_variable_definition = self.language_db["$local-variable-defs"](variable_db.get())

        # Put all things together
        txt = []
        txt.append(bwd_prolog.replace("$$ID$$", repr(sm.get_id()).replace("L", "")))
        txt.extend(local_variable_definition)
        txt.extend(comment)
        txt.extend(function_body)
        txt.extend(terminal)
        txt.append(state_router_txt)
        txt.append(bwd_epilog.replace("$$INIT_STATE_ID$$", get_label_of_address(sm.init_state_index)))

        return get_plain_strings(txt)
Exemple #3
0
    def analyzer_function_get(self, RequiredLocalVariablesDB):
        routed_address_set = set([])
        function_body      = []

        # (*) Core State Machine
        #     All pattern detectors combined in single forward analyzer
        dsm = StateMachineDecorator(self.sm, 
                                    self.state_machine_name, 
                                    self.post_contexted_sm_id_list, 
                                    BackwardLexingF=False, 
                                    BackwardInputPositionDetectionF=False)

        variable_db.init(RequiredLocalVariablesDB)
        init_address_handling(dsm.get_direct_transition_to_terminal_db())

        # (*) Pre Context State Machine
        #     All pre-context combined in single backward analyzer.
        if self.pre_context_sm_list != []:
            code = self.__backward_analyzer()
            function_body.extend(code)
            
        # -- now, consider core state machine
        code = self.__forward_analyzer(dsm)
        function_body.extend(code)

        # At this point in time, the function body is completely defined
        routed_address_set = get_address_set_subject_to_routing()

        if len(routed_address_set) != 0 or is_label_referenced("$state-router"):
            routed_state_info_list = state_router.get_info(routed_address_set, dsm)
            function_body.append(state_router.do(routed_state_info_list))
            variable_db.require("target_state_index", Condition_ComputedGoto=False) 

        if is_label_referenced("$reload-FORWARD") or is_label_referenced("$reload-BACKWARD"):
            variable_db.require("target_state_else_index")
            variable_db.require("target_state_index")

        # Following function refers to the global 'variable_db'
        variable_definitions = self.language_db["$variable-definitions"](self.post_contexted_sm_id_list,
                                                                         self.pre_context_sm_id_list, 
                                                                         self.language_db)

        # (*) Pack Pre-Context and Core State Machine into a single function
        analyzer_function = self.language_db["$analyzer-func"](self.state_machine_name, 
                                                               self.analyzer_state_class_name, 
                                                               self.stand_alone_analyzer_f,
                                                               variable_definitions, 
                                                               function_body, 
                                                               self.mode_name_list, 
                                                               LanguageDB=self.language_db)

        return get_plain_strings(analyzer_function)
Exemple #4
0
    def backward_detector_function_get(self, sm):
        assert sm.get_orphaned_state_index_list() == []

        dsm = StateMachineDecorator(sm,
                                    "BACKWARD_DETECTOR_" + repr(sm.get_id()),
                                    PostContextSM_ID_List=[],
                                    BackwardLexingF=True,
                                    BackwardInputPositionDetectionF=True)

        variable_db.init()
        init_address_handling(dsm.get_direct_transition_to_terminal_db())

        function_body = state_machine_coder.do(dsm)

        comment = []
        if Setup.comment_state_machine_transitions_f:
            comment = Setup.language_db["$ml-comment"]("BEGIN: BACKWARD DETECTOR STATE MACHINE\n" + \
                                                       sm.get_string(NormalizeF=False)            + \
                                                       "\nEND: BACKWARD DETECTOR STATE MACHINE")
            comment.append("\n")

        # -- input position detectors simply the next 'catch' and return
        terminal = []
        terminal.append("\n")
        terminal.append("    __quex_assert_no_passage();\n")
        terminal.append(get_label("$terminal-general-bw") + ":\n")
        terminal.append("    " + self.language_db["$input/seek_position"]
                        ("end_of_core_pattern_position") + "\n")
        terminal.append("    " + self.language_db["$input/increment"] + "\n")
        terminal.append("    return;\n")

        routed_address_set = get_address_set_subject_to_routing()

        state_router_txt = ""
        if len(routed_address_set) != 0:
            routed_state_info_list = state_router.get_info(
                routed_address_set, dsm)
            state_router_txt = state_router.do(routed_state_info_list)
            variable_db.require("target_state_index",
                                Condition_ComputedGoto=False)

        variable_db.require("input")
        variable_db.require("end_of_core_pattern_position")

        local_variable_definition = self.language_db["$local-variable-defs"](
            variable_db.get())

        # Put all things together
        txt = []
        txt.append(
            bwd_prolog.replace("$$ID$$",
                               repr(sm.get_id()).replace("L", "")))
        txt.extend(local_variable_definition)
        txt.extend(comment)
        txt.extend(function_body)
        txt.extend(terminal)
        txt.append(state_router_txt)
        txt.append(
            bwd_epilog.replace("$$INIT_STATE_ID$$",
                               get_label_of_address(sm.init_state_index)))

        return get_plain_strings(txt)