WO2018161509A1 - Conditional compilation preprocessing method, terminal and storage medium - Google Patents
Conditional compilation preprocessing method, terminal and storage medium Download PDFInfo
- Publication number
- WO2018161509A1 WO2018161509A1 PCT/CN2017/099747 CN2017099747W WO2018161509A1 WO 2018161509 A1 WO2018161509 A1 WO 2018161509A1 CN 2017099747 W CN2017099747 W CN 2017099747W WO 2018161509 A1 WO2018161509 A1 WO 2018161509A1
- Authority
- WO
- WIPO (PCT)
- Prior art keywords
- program text
- event
- original program
- action
- processing
- Prior art date
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/40—Transformation of program code
- G06F8/41—Compilation
- G06F8/42—Syntactic analysis
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/40—Transformation of program code
- G06F8/41—Compilation
- G06F8/42—Syntactic analysis
- G06F8/423—Preprocessors
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/40—Transformation of program code
- G06F8/41—Compilation
- G06F8/42—Syntactic analysis
- G06F8/425—Lexical analysis
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/40—Transformation of program code
- G06F8/41—Compilation
- G06F8/43—Checking; Contextual analysis
- G06F8/436—Semantic checking
- G06F8/437—Type checking
Definitions
- the present application relates to the field of computer processing, and in particular, to a conditional pre-processing method, a terminal, and a storage medium.
- C language is a compiled high-level language. Developers can make full use of conditional compilation features to support multiple soft/hard configurations in the same project, but when the application is cross-platform. It is necessary to separately generate versions under the respective platforms, and it is difficult to develop.
- Interpretive languages eg, WMLScript
- WMLScript can be cross-platform, and development is less difficult than C, but interpreted languages do not have conditional compilation.
- conditional compilation preprocessing method a terminal, and a storage medium are provided.
- a conditional compilation preprocessing method including:
- the original program text is processed correspondingly according to the determined processing action, and the processed target program text is output.
- a terminal comprising a memory and a processor, the memory storing computer readable instructions, the computer readable instructions being executed by the processor such that the processor performs the following steps:
- the original program text is processed correspondingly according to the determined processing action, and the processed target program text is output.
- One or more non-transitory readable storage mediums storing computer readable instructions, when executed by one or more processors, cause the one or more processors to perform the following steps:
- the original program text is processed correspondingly according to the determined processing action, and the processed target program text is output.
- FIG. 1 is a block diagram showing the internal structure of a terminal in an embodiment
- FIG. 2 is a flow chart of a conditional compilation preprocessing method in an embodiment
- FIG. 3 is a flow chart of a method for determining a corresponding processing action according to a current state and an event in an embodiment
- FIG. 4 is a flowchart of a method for outputting a processed target program text according to a determined processing action according to a determined processing action;
- FIG. 5 is a schematic diagram of implementing conditional compilation preprocessing in one embodiment
- Figure 6 is a block diagram showing the structure of a terminal in an embodiment.
- the internal structure of the terminal 102 is as shown in FIG. 1, including a processor connected through a system bus, an internal memory, a non-volatile storage medium, a network interface, a display screen, and an input device.
- the non-volatile storage medium of the terminal 102 stores an operating system and computer readable instructions executable by the processor to implement the terminal 102.
- the processor is used to provide computing and control capabilities to support the operation of the entire terminal.
- the internal memory in the terminal stores computer readable instructions that, when executed by the processor, cause the processor to perform a conditional compilation preprocessing method.
- the network interface is used to connect to the network for communication.
- the display screen of the terminal 102 may be a liquid crystal display or an electronic ink display screen.
- the input device may be a touch layer covered on the display screen, or may be a button, a trackball or a touchpad provided on the outer casing of the electronic device, or may be An external keyboard, trackpad, or mouse.
- the terminal can be a POS machine, a tablet computer, a notebook computer, a desktop computer, or the like.
- FIG. 1 is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the terminal to which the solution of the present application is applied.
- the specific terminal may include a ratio. More or fewer components are shown in the figures, or some components are combined, or have different component arrangements.
- conditional compilation preprocessing method is proposed, which is applicable to the terminal shown in FIG. 1, and includes the following steps:
- Step 202 Acquire original program text to be processed.
- conditional compilation in order to enable the interpretation language (for example, WMLScript) to implement the conditional compilation feature, a preprocessing method suitable for conditional compilation in an interpreted language is proposed by simulating the C language for conditional compilation.
- the nature of conditional compilation can be simply understood as: analyzing the original program text, retaining or deleting a certain piece of code according to the "specified condition", and outputting the processed program text, that is, by retaining or deleting a certain piece of code according to the specified condition. Select the target program text that meets the requirements in the program text.
- the terminal In order to filter the original program text, the terminal first needs to obtain the original program text to be processed.
- the original program text refers to the original program code that is written, that is, the program text before processing.
- Step 204 Analyze the original program text, match the corresponding keyword according to the preset regular expression, and output a mark corresponding to the keyword.
- the terminal After the terminal obtains the original program text to be processed, it is possible to accurately determine whether the "specified condition" is met. First, by analyzing the original program text, matching the corresponding keyword according to the preset regular expression, and then outputting a token corresponding to the matched keyword. Its In the middle, the matching relationship between the regular expression and the keyword and the correspondence between the keyword and the mark are set in advance.
- the original program text can be analyzed using a lexical analyzer generated by lex, where lex is a lexical scan code generator that generates a lexical scan code, ie, a lexical analyzer, based on the defined pattern file, the main pattern file.
- Regular expressions are used to define matching rules, as well as actions that are performed after matching, such as executing a return token. That is, the lexical analyzer can be used to analyze the original program text, match the keyword according to the preset regular expression, and then output the mark corresponding to the keyword.
- the following problems need to be solved when using the lexical analyzer to analyze the original program text.
- One is to ignore the comments and ignore all the text in the comments.
- the second is to ignore any data in the string, that is, ignore the string enclosed by the quote "".
- the third is to record the current line number.
- the record line number is very important for subsequent processing, because the final processing depends on the line number to process the original program text.
- the fourth is to return a token corresponding to the keyword, so that the subsequent grammar matching according to the token is facilitated.
- the keywords include #if, #ifdef, #ifndef, #elif, #else, #defined, #endif, #define, #undef, etc.
- the corresponding tags can be set to: IF, IFDEF, IFNDEF, ELIF, ELSE, DEFINED, ENDIF, DEFINE, etc.
- the fifth is to return the macro name and macro value.
- Step 206 Compile the corresponding event according to the markup and the preset conditional compilation grammar rule.
- the correspondence between the conditional compilation grammar rules and the event is preset in the terminal.
- the tag is matched to a certain grammar rule, and then the corresponding event is determined according to the matched grammar rule, and the corresponding event is output.
- the event facilitates subsequent determination of the corresponding processing action based on the event.
- an event is a signal that something happens in a program.
- the terminal can match the corresponding event by using a parser to compile the grammar rules according to the mark and the preset condition.
- the terminal first launches a parser, and the parser internally calls a lexer that matches the tokens output by the lexer and predefined conditional compilation grammar rules. The corresponding event.
- the parser can be implemented by Yacc, which is a parsing code generator that generates a parser based on the defined grammar file.
- the grammar file uses the Backus-Naur Form to describe the grammar rules. It uses the tokens exported by lex and its own defined grammar rules to match and execute the corresponding actions (for example, executing a piece of C code). As shown in Table 1, an illustration of the event and corresponding conditional compilation syntax rules is shown.
- Step 208 Determine a corresponding processing action according to the current state and the event.
- the terminal after the terminal matches the corresponding event according to the mark and the preset conditional compilation grammar rule, the terminal acquires the current state, and determines a corresponding processing action according to the current state and the event.
- a relationship table between the processing action and the current state and the event may be pre-stored, and the corresponding processing action may be determined after the current state and the event are obtained, wherein the processing action may be deleting or retaining a certain piece of code.
- the event is output to the state processor, and the state in the state processor is driven to jump, that is, jump from one state to another state. Then according to the jump to another A state determines the corresponding processing action.
- the parser, the state processor, etc. are all software implementations inside the terminal.
- the state processor compiles the syntax characteristics according to conditions, and the state processor stores and manages the state in a stack (ie, maintains a state stack). As shown in Table 2, the predefined states and corresponding state descriptions are shown. The next state is determined by acquiring the current state and the matched event (refer to Table 3), and then determining the corresponding processing action.
- Step 210 Perform corresponding processing on the original program text according to the determined processing action, and output the processed target program text.
- the terminal after determining the processing action, performs corresponding processing on the original program text according to the determined processing action, and outputs the processed target program text, and the output target program text is filtered according to the specified condition.
- the terminal adds a corresponding processing action to the motion processor's action list according to the next state by the state processor, and then the action processor performs corresponding processing according to the processing action in the action list, for example, deleting the corresponding row or
- the pre-compilation method is not reduced by using the condition. Maintenance costs and reduced resources Consumption.
- the steps of determining a corresponding processing action based on the current state and the event include:
- step 208A the next state is determined according to the current state and the event.
- the current state is obtained, and the next state corresponding to the current state and the event is searched by querying the state table.
- Table 3 it is a state table in one embodiment.
- the first column of the vertical axis represents the current state
- the horizontal axis is the first behavior event
- the other cells indicate the next state when the current state receives the event.
- the current state is the initial state, that is, STATE_INITIAL
- the event that occurs is EVENT_IF_TRUE.
- the state table that is, Table 3
- the corresponding next state is STATE_IF_TRUE (ie, the cell corresponding to the third row and the second column).
- step 208B the corresponding processing action is determined according to the next state.
- the corresponding processing action is determined according to the next state.
- the action taken in the next step can be distinguished.
- Pre-defined types of actions for example, actions are divided into two categories, one is to delete the current line (for example, if, else, elif their own line), the corresponding next state is: STATE_IF_TRUE, STATE_ELSE_TRUE, STATE_ELIF_TRUE, STATE_ENDIF; Is to delete multiple rows, the corresponding next state is: STATE_IF_FALSE, STATE_IF_INHERIT_FALSE, STATE_ELSE_FALSE, STATE_ELIF_FALSE.
- the original program text is processed correspondingly according to the determined processing action, and the step of outputting the processed target program text includes:
- Step 210A adding the determined processing action to the action list.
- the determined action is added to the action list.
- the terminal first matches the event by the parser, and then the event drives the jump of the state processor, after which the state processor determines the next state according to the current state and the event by querying the state table, and then determines the corresponding according to the next state.
- the processing action, and then the determined action is added to the action list of the action processor, so that the subsequent action processor performs corresponding processing according to the action in the action list, wherein the parser, the state processor, the action processor, etc. are all Software implementation inside the terminal.
- Step 210B Perform a corresponding processing operation on the original program text according to the action list, and output the processed target program text.
- the terminal adds the processing action to the motion processor through the state processor.
- the action processor executes the original program text according to the saved series of processing actions. Corresponding operation; one is that whenever an action is added to the action list, the action processor starts executing the corresponding processing action, and then outputs the processed program text, that is, the target program text. For example, according to the typical conditional compilation process #if true...#else...#endif, the final processing action is 1) delete the #if true line itself; 2) delete #else() to the endif All lines between (inclusive).
- the action processor does not actually delete the line of code, but adds a line comment "//" before the code.
- the processed target program text is output. If there is a compiling process later, the output is output to the compiler for processing, thereby implementing conditional compilation.
- the step of compiling the corresponding event according to the markup and the preset conditional compilation grammar rule comprises: matching the grammar rule according to the mark and the preset condition, and when matching the conditional statement containing the macro name, The macro definition manager queries the definition corresponding to the macro name and the corresponding value for conditional judgment, and matches the corresponding event according to the result of the conditional judgment.
- the macro definition manager is used to manage the macro definition, and the conditional judgment of the conditional compilation sometimes requires content based on the macro definition.
- the macro definition manager When matching the conditional statement containing the macro name, it is necessary to query the macro definition manager for the macro value corresponding to the matched macro name, so as to facilitate the conditional judgment according to the macro value, that is, whether the condition is TRUE or FALSE.
- the macro definition contains two major categories, one is the global macro definition -D passed in through the command line parameters, and the other is the macro defined by the file #define. A locally defined macro overrides the global definition and only affects the behavior behind the line in this file, and has no effect on other files.
- the information of the macro record records the state of the macro, the macro name, the macro value, and the macro line number in addition to the macro type, that is, the global macro and the local macro.
- Macro states include available, temporarily disabled, and invalid. Among them, the temporary invalid state applies to the global macro, which means that it is defined with -D but is canceled in a file (#undef). This state only affects the file itself. When another file is processed, -D is still restored. State; invalid state applies to local macros, indicating that they are canceled (#undef) in a file.
- the macro line number in the macro definition manager is only valid for local macros. It is mainly used to give a warning when the same macro definition is found twice in the same file.
- the current definition is in which row.
- the local macro is detected first. If it does not exist, the global macro is checked. In one embodiment, when the following statement #ifdef NAME, #ifndef NAME, #if NAME, #elif NAME, #if defined(NAME) is encountered, the macro definition manager needs to be queried to see if the definition and the corresponding value are What, if not found, returns NULL to indicate that the definition could not be found.
- the corresponding macro definition is added or deleted in the macro definition manager according to the type of the definition statement.
- the terminal since the condition determination needs to be based on the macro definition in the macro definition manager, it is first necessary to add a macro definition in the macro definition manager, and if it is found later, it is also required to be in the macro definition.
- the corresponding macro definition is removed from the manager. Specifically, first, the terminal performs matching according to a preset regular expression by the lexical analyzer, and outputs a corresponding mark, wherein the mark includes a mark representing a macro name. For example, when matching the keyword #define NAME VALUE, #define NAME, or #undef NAME, the name of the macro is returned. That is, when matching the define, undef keyword, the corresponding text is stored (the real macro name is stored) and the tag NAME is returned.
- the parser performs matching according to the markup and the preset conditional compilation grammar rule.
- the definition statement containing the macro name the corresponding macro definition is added or deleted in the macro definition manager according to the type of the definition statement.
- the macro definition statement refers to a statement containing definition words such as #define, #undef.
- the statement is divided into two types: definition and undefine.
- the statement containing #define represents the statement of the defined type
- the statement containing #undef represents the statement of the undefined type.
- the macro definition manager is added to the macro definition manager when it encounters the following statement #define NAME, #define NAME VALUE, and the macro definition manager is deleted when it encounters #undef NAME.
- the step of analyzing the original program text, matching the corresponding keyword according to the preset regular expression and outputting the corresponding mark includes: analyzing the original program text according to the preset regular expression Match the corresponding keyword, record the line number where the keyword is located, and output The corresponding tag and the corresponding line number.
- the lexical analyzer in order to facilitate the execution of the determined processing action, after analyzing the original program text and matching the corresponding keywords, not only the token corresponding to the keyword needs to be output, but also each matching is required to be recorded.
- the line number of the keyword is output and output. Recording the line number is very important for subsequent processing because the action processor ultimately relies on the line number to process the program text.
- the specific implementation means that by adding a c function for increasing the line number, the lexical analyzer then calls the function to increase the global line number. For example, whenever you encounter " ⁇ n", call the c function to increase the global line number.
- the processing of the original program text is performed according to the determined processing action
- the step 210 of outputting the processed target program text includes: performing a corresponding processing action according to the type of the processing action and the corresponding line number, and outputting the processing After the target program text.
- the action processor executes the corresponding processing action according to the type of the processing action and the corresponding line number, and then outputs the processed process.
- Target program text The types of processing actions can be divided into two categories: one is to delete the current row; the other is to delete multiple rows.
- each processing action corresponds to a start line number and an end line number information.
- the first type of action can be treated as a special case with the same starting line number and ending line number.
- the ending line number and the starting line number can be temporarily written to the same value, when the next event generates a new action.
- the processing action is corresponding to the next state determined by the state processor.
- the next state is: STATE_IF_TRUE, STATE_ELSE_TRUE, STATE_ELIF_TRUE, STATE_ENDIF
- the corresponding action is: deleting the current row.
- next state is: STATE_IF_FALSE, STATE_IF_INHERIT_FALSE, STATE_ELSE_FALSE, STATE_ELIF_FALSE
- the corresponding action is: delete multiple rows.
- the determined next state is STATE_IF_TRUE
- the current row needs to be deleted, that is, the starting row number and the ending row number are the same.
- STATE_IF_FALSE it means that multiple rows need to be deleted, but it is not known to delete a few rows, that is, I don't know what the ending line number is.
- next event occurs, assuming that the new event is EVENT_ELSE_TRUE, then the corresponding next state is STATE_ELSE_TRUE, indicating that the current line is deleted, and the current line number is reduced before deleting the current line. Go to 1, as the end line number of the previous event.
- the method for implementing the above conditional compilation is specifically performed by a lexical analyzer, a parser, a state processor, an action processor, and a macro definition manager.
- the main program will add the global macro to the macro definition manager.
- the main program in the terminal performs the following operations on each original program text, a), the main program Enable the parser, the parser internally calls the lexical analyzer, analyzes the original program text through the lexical analyzer to match the corresponding keyword and outputs the corresponding token, and then the parser uses the token output by the lexical analyzer. (token) and pre-defined grammar rules, corresponding events are generated.
- the macro definition manager is added, deleted, and checked according to the matched statement containing the macro name; b) the parser The event is output to the state processor, which drives the jump of the state machine.
- the state processor determines the corresponding processing action according to the next state, and adds the processing action to the action processor.
- the main program executes the action list in the processor in order, and outputs the processed program text, that is, the target program text.
- the lexical analyzer, the parser, the state processor, the action processor and the macro definition manager respectively implement preprocessing of the conditional compilation by mutual cooperation, and implement the conditional compiling preprocessor corresponding to the preprocessing method of the conditional compilation.
- the execution file is only about 36k.
- conditional compilation preprocessor It is a lightweight conditional compilation preprocessor. If there is a subsequent compilation process, you only need to add the conditional compilation preprocessor command before the standard compilation process to facilitate integration.
- the method is applicable to multiple languages, such as WMLScript, JavaScript, Java, Python, etc. Since different programming languages have different specifications, you can quickly adapt to any language by fine-tuning lexical and grammatical rules files as needed. Therefore, it is also versatile and easy to expand.
- the embodiment of the present application provides a terminal.
- the internal structure of the terminal may correspond to the structure shown in FIG. 1.
- Each of the following modules may be implemented in whole or in part by software, hardware, or a combination thereof.
- the terminal 600 in this embodiment includes:
- the obtaining module 602 is configured to obtain the original program text to be processed.
- the output module 604 is configured to analyze the original program text, match the corresponding keyword according to the preset regular expression, and output a corresponding mark.
- the matching module 606 is configured to match the corresponding event according to the markup and the preset conditional compilation grammar rule.
- the determining module 608 is configured to determine a corresponding processing action according to the current state and the event.
- the processing module 610 is configured to perform corresponding processing on the original program text according to the determined processing action, and output the processed target program text.
- the determining module is further configured to determine a next state according to the current state and the event, and determine a corresponding processing action according to the next state.
- the processing module is further configured to add the determined processing action to the action list, perform a corresponding processing action on the original program text according to the action list, and output the processed target program text.
- the matching module is further configured to perform matching according to the markup and the preset conditional compilation grammar rule, and when matching the conditional statement containing the macro name, query the macro definition manager to query the definition corresponding to the macro name and corresponding The value is judged by the condition, and the corresponding event is matched according to the result of the conditional judgment.
- the output module is further configured to analyze the original program text, match the corresponding keyword according to the preset regular expression, record the line number where the keyword is located, and output the corresponding mark and the corresponding line number.
- the processing module is further configured to execute a corresponding processing action according to the type of the processing action and the corresponding line number, and output the processed target program text.
- the storage medium may be a non-volatile storage medium such as a magnetic disk, an optical disk, a read-only memory (ROM), or a random access memory (RAM).
Landscapes
- Engineering & Computer Science (AREA)
- General Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Software Systems (AREA)
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- Computational Linguistics (AREA)
- Devices For Executing Special Programs (AREA)
Abstract
A conditional compilation preprocessing method, comprising: acquiring an original program text to be processed (202), analyzing the original program text, discovering a corresponding matching keyword according to a preset regular expression, and outputting a corresponding label (204), discovering a corresponding matching event according to the label and preset conditional compilation syntax rules (206), determining, according to the current state and the event, a corresponding processing action (208), and performing corresponding processing of the original program text according to the determined processing action, and outputting a processed target program text (210).
Description
本申请要求于2017年3月8日提交中国专利局、申请号为201710135974.4、发明名称为“条件编译预处理方法和装置”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。This application claims the priority of the Chinese Patent Application, filed on March 8, 2017, the application Serial No. .
本申请涉及计算机处理领域,特别是涉及一种条件编译预处理方法、终端及存储介质。The present application relates to the field of computer processing, and in particular, to a conditional pre-processing method, a terminal, and a storage medium.
传统POS应用开发普遍采用C语言进行开发,C语言是一种编译型高级语言,开发人员可以充分利用条件编译的特性,在同一个工程中支持多种软/硬配置,但是当应用在跨平台时必须分别生成各自平台下的版本,而且开发难度较大。解释型语言(比如,WMLScript)可以做到跨平台,而且相对C语言来说,开发难度较低,但是解释型语言不具有条件编译的特性。Traditional POS application development is generally developed in C language. C language is a compiled high-level language. Developers can make full use of conditional compilation features to support multiple soft/hard configurations in the same project, but when the application is cross-platform. It is necessary to separately generate versions under the respective platforms, and it is difficult to develop. Interpretive languages (eg, WMLScript) can be cross-platform, and development is less difficult than C, but interpreted languages do not have conditional compilation.
在典型的POS软件项目中,往往同一个项目需要支持多种配置,且这些机型应用逻辑差异并不大,有了条件编译就可以实现同一个工程支持不同配置,但是如果选择解释型语言作为开发语言,由于不具有条件编译功能,那么当一套应用要适用多种配置时,要么复制代码,各自建立工程,要么通过变量控制程序流程。而复制代码的做法会造成维护成本高,通过变量控制的做法会增加资源的消耗。因此,亟待需要提出一种使得解释型语言也能够实现条件编译的方法。In a typical POS software project, often the same project needs to support multiple configurations, and the application logic of these models is not very different. With the conditional compilation, the same project can support different configurations, but if you choose an interpreted language as the Development language, because there is no conditional compilation function, when a set of applications to apply a variety of configurations, either copy the code, build the project, or control the program flow through variables. The practice of copying the code will result in high maintenance costs, and the practice of controlling by variables will increase the consumption of resources. Therefore, there is an urgent need to propose a method for enabling an interpreted language to be conditionally compiled.
发明内容
Summary of the invention
根据本申请的各种实施例,提供一种条件编译预处理方法、终端及存储介质。According to various embodiments of the present application, a conditional compilation preprocessing method, a terminal, and a storage medium are provided.
一种条件编译预处理方法,包括:A conditional compilation preprocessing method, including:
获取待处理的原程序文本;Obtain the original program text to be processed;
对所述原程序文本进行分析,根据预设的正则表达式匹配出对应的关键字,输出与所述关键字相应的标记;Parsing the original program text, matching corresponding keywords according to a preset regular expression, and outputting a mark corresponding to the keyword;
根据所述标记和预设的条件编译语法规则匹配出相应的事件;Compiling the corresponding event according to the mark and the preset conditional compilation grammar rule;
根据当前状态和所述事件确定相应的处理动作;及Determining corresponding processing actions according to the current state and the event; and
根据确定的所述处理动作对所述原程序文本进行对应的处理,输出处理后的目标程序文本。The original program text is processed correspondingly according to the determined processing action, and the processed target program text is output.
一种终端,包括存储器和处理器,所述存储器中存储有计算机可读指令,所述计算机可读指令被所述处理器执行时,使得所述处理器执行以下步骤:A terminal comprising a memory and a processor, the memory storing computer readable instructions, the computer readable instructions being executed by the processor such that the processor performs the following steps:
获取待处理的原程序文本;Obtain the original program text to be processed;
对所述原程序文本进行分析,根据预设的正则表达式匹配出对应的关键字,输出与所述关键字相应的标记;Parsing the original program text, matching corresponding keywords according to a preset regular expression, and outputting a mark corresponding to the keyword;
根据所述标记和预设的条件编译语法规则匹配出相应的事件;Compiling the corresponding event according to the mark and the preset conditional compilation grammar rule;
根据当前状态和所述事件确定相应的处理动作;及Determining corresponding processing actions according to the current state and the event; and
根据确定的所述处理动作对所述原程序文本进行对应的处理,输出处理后的目标程序文本。The original program text is processed correspondingly according to the determined processing action, and the processed target program text is output.
一个或多个存储有计算机可读指令的非易失性可读存储介质,所述计算机可读指令被一个或多个处理器执行时,使得所述一个或多个处理器执行以下步骤:One or more non-transitory readable storage mediums storing computer readable instructions, when executed by one or more processors, cause the one or more processors to perform the following steps:
获取待处理的原程序文本;Obtain the original program text to be processed;
对所述原程序文本进行分析,根据预设的正则表达式匹配出对应的关键字,输出与所述关键字相应的标记;Parsing the original program text, matching corresponding keywords according to a preset regular expression, and outputting a mark corresponding to the keyword;
根据所述标记和预设的条件编译语法规则匹配出相应的事件;Compiling the corresponding event according to the mark and the preset conditional compilation grammar rule;
根据当前状态和所述事件确定相应的处理动作;及
Determining corresponding processing actions according to the current state and the event; and
根据确定的所述处理动作对所述原程序文本进行对应的处理,输出处理后的目标程序文本。The original program text is processed correspondingly according to the determined processing action, and the processed target program text is output.
本申请的一个或多个实施例的细节在下面的附图和描述中提出。本申请的其它特征、目的和优点将从说明书、附图以及权利要求书变得明显。Details of one or more embodiments of the present application are set forth in the accompanying drawings and description below. Other features, objects, and advantages of the invention will be apparent from the description and appended claims.
为了更清楚地说明本申请实施例或现有技术中的技术方案,下面将对实施例或现有技术描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本申请的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings to be used in the embodiments or the prior art description will be briefly described below. Obviously, the drawings in the following description are only It is a certain embodiment of the present application, and other drawings can be obtained according to the drawings without any creative work for those skilled in the art.
图1为一个实施例中终端的内部结构框图;1 is a block diagram showing the internal structure of a terminal in an embodiment;
图2为一个实施例中条件编译预处理方法流程图;2 is a flow chart of a conditional compilation preprocessing method in an embodiment;
图3为一个实施例中根据当前状态和事件确定相应的处理动作的方法流程图;3 is a flow chart of a method for determining a corresponding processing action according to a current state and an event in an embodiment;
图4为一个实施例中根据确定的处理动作对原程序文本进行对应的处理,输出处理后的目标程序文本的方法流程图;4 is a flowchart of a method for outputting a processed target program text according to a determined processing action according to a determined processing action;
图5为一个实施例中实现条件编译预处理的示意图;FIG. 5 is a schematic diagram of implementing conditional compilation preprocessing in one embodiment; FIG.
图6为一个实施例中终端的结构框图。Figure 6 is a block diagram showing the structure of a terminal in an embodiment.
为了使本申请的目的、技术方案及优点更加清楚明白,以下结合附图及实施例,对本申请进行进一步详细说明。应当理解,此处所描述的具体实施例仅仅用以解释本申请,并不用于限定本申请。In order to make the objects, technical solutions, and advantages of the present application more comprehensible, the present application will be further described in detail below with reference to the accompanying drawings and embodiments. It is understood that the specific embodiments described herein are merely illustrative of the application and are not intended to be limiting.
如图1所示,在一个实施例中,终端102的内部结构如图1所示,包括通过系统总线连接的处理器、内存储器、非易失性存储介质、网络接口、显示屏和输入装置。其中,终端102的非易失性存储介质存储有操作系统和计算机可读指令,该计算机可读指令可被处理器执行以实现适用于终端102的
一种条件编译预处理方法。该处理器用于提供计算和控制能力,支撑整个终端的运行。终端中的内存储器中存有计算机可读指令,该计算机可读指令被处理器执行时,可使得处理器执行一种条件编译预处理方法。网络接口用于连接到网络进行通信。终端102的显示屏可以是液晶显示屏或者电子墨水显示屏等,输入装置可以是显示屏上覆盖的触摸层,也可以是电子设备外壳上设置的按键、轨迹球或触控板,也可以是外接的键盘、触控板或鼠标等。该终端可以是POS机、平板电脑、笔记本电脑、台式计算机等。本领域技术人员可以理解,图1中示出的结构,仅仅是与本申请方案相关的部分结构的框图,并不构成对本申请方案所应用于其上的终端的限定,具体的终端可以包括比图中所示更多或更少的部件,或者组合某些部件,或者具有不同的部件布置。As shown in FIG. 1, in one embodiment, the internal structure of the terminal 102 is as shown in FIG. 1, including a processor connected through a system bus, an internal memory, a non-volatile storage medium, a network interface, a display screen, and an input device. . Wherein, the non-volatile storage medium of the terminal 102 stores an operating system and computer readable instructions executable by the processor to implement the terminal 102.
A conditional compilation preprocessing method. The processor is used to provide computing and control capabilities to support the operation of the entire terminal. The internal memory in the terminal stores computer readable instructions that, when executed by the processor, cause the processor to perform a conditional compilation preprocessing method. The network interface is used to connect to the network for communication. The display screen of the terminal 102 may be a liquid crystal display or an electronic ink display screen. The input device may be a touch layer covered on the display screen, or may be a button, a trackball or a touchpad provided on the outer casing of the electronic device, or may be An external keyboard, trackpad, or mouse. The terminal can be a POS machine, a tablet computer, a notebook computer, a desktop computer, or the like. A person skilled in the art can understand that the structure shown in FIG. 1 is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the terminal to which the solution of the present application is applied. The specific terminal may include a ratio. More or fewer components are shown in the figures, or some components are combined, or have different component arrangements.
如图2所示,在一个实施例中,提出了一种条件编译预处理方法,该方法可应用于如图1所示的终端中,其包括以下步骤:As shown in FIG. 2, in an embodiment, a conditional compilation preprocessing method is proposed, which is applicable to the terminal shown in FIG. 1, and includes the following steps:
步骤202,获取待处理的原程序文本。Step 202: Acquire original program text to be processed.
在本实施例中,为了使得解释型语言(比如,WMLScript)也能够实现条件编译的特性,通过模拟C语言进行条件编译的功能,提出一种适用于解释型语言进行条件编译的预处理方法。其中,条件编译的本质可以简单的理解为:分析原程序文本,根据“指定条件”保留或删除某段代码,并输出处理后的程序文本,即根据指定条件通过保留或删除某段代码从原程序文本中挑选出符合要求的目标程序文本。为了对原程序文本进行筛选,终端首先需要获取待处理的原程序文本,原程序文本是指编写的原程序代码,即处理之前的程序文本。In this embodiment, in order to enable the interpretation language (for example, WMLScript) to implement the conditional compilation feature, a preprocessing method suitable for conditional compilation in an interpreted language is proposed by simulating the C language for conditional compilation. Among them, the nature of conditional compilation can be simply understood as: analyzing the original program text, retaining or deleting a certain piece of code according to the "specified condition", and outputting the processed program text, that is, by retaining or deleting a certain piece of code according to the specified condition. Select the target program text that meets the requirements in the program text. In order to filter the original program text, the terminal first needs to obtain the original program text to be processed. The original program text refers to the original program code that is written, that is, the program text before processing.
步骤204,对原程序文本进行分析,根据预设的正则表达式匹配出对应的关键字,输出与关键字相应的标记。Step 204: Analyze the original program text, match the corresponding keyword according to the preset regular expression, and output a mark corresponding to the keyword.
其中,终端获取到待处理的原程序文本后,为了能够精确地判断是否符合“指定条件”。首先,通过对原程序文本进行分析,根据预设的正则表达式匹配对应的关键字,然后输出与该匹配到的关键字相应的标记(token)。其
中,预先设置了正则表达式和关键字之间的匹配关系以及关键字与标记之间的对应关系。在一个实施例中,可用采用lex生成的词法分析器对原程序文本进行分析,其中,lex是词法扫描代码生成器,它根据定义的模式文件生成词法扫描代码即词法分析器,模式文件中主要使用正则表达式来定义匹配规则,以及匹配后执行的动作,比如,执行返回标记(token)。即可以使用词法分析器对原程序文本进行分析,根据预设的正则表达式匹配出关键字,然后输出与关键字对应的标记。After the terminal obtains the original program text to be processed, it is possible to accurately determine whether the "specified condition" is met. First, by analyzing the original program text, matching the corresponding keyword according to the preset regular expression, and then outputting a token corresponding to the matched keyword. Its
In the middle, the matching relationship between the regular expression and the keyword and the correspondence between the keyword and the mark are set in advance. In one embodiment, the original program text can be analyzed using a lexical analyzer generated by lex, where lex is a lexical scan code generator that generates a lexical scan code, ie, a lexical analyzer, based on the defined pattern file, the main pattern file. Regular expressions are used to define matching rules, as well as actions that are performed after matching, such as executing a return token. That is, the lexical analyzer can be used to analyze the original program text, match the keyword according to the preset regular expression, and then output the mark corresponding to the keyword.
在另一个实施例中,在使用词法分析器对原程序文本进行分析时还需要解决以下几个问题,一是忽略注释,对注释中的所有文本均需忽略。二是忽略字符串中的任何数据,即忽略引号“”包围的字符串。三是记录当前所在行号,记录行号对后续处理非常重要,因为最终进行处理依赖于行号对原程序文本进行处理的。四是返回与关键字对应的标记(token),便于后续根据标记进行语法的匹配。其中,关键字包括#if,#ifdef,#ifndef,#elif,#else,#defined,#endif,#define,#undef等,相应的标记可以设置为:IF,IFDEF,IFNDEF,ELIF,ELSE,DEFINED,ENDIF,DEFINE等。五是返回宏名称和宏值,当词法分析器匹配到#define、#undef关键字时,将对应的宏名称及宏值进行保存,并返回与宏的名称和宏值对应的标记:NAME、MACROVALUE,便于后续语法分析器根据匹配到的宏名称和值进行宏操作,比如,在宏定义管理器中增加或删除对应的宏定义。In another embodiment, the following problems need to be solved when using the lexical analyzer to analyze the original program text. One is to ignore the comments and ignore all the text in the comments. The second is to ignore any data in the string, that is, ignore the string enclosed by the quote "". The third is to record the current line number. The record line number is very important for subsequent processing, because the final processing depends on the line number to process the original program text. The fourth is to return a token corresponding to the keyword, so that the subsequent grammar matching according to the token is facilitated. Among them, the keywords include #if, #ifdef, #ifndef, #elif, #else, #defined, #endif, #define, #undef, etc., the corresponding tags can be set to: IF, IFDEF, IFNDEF, ELIF, ELSE, DEFINED, ENDIF, DEFINE, etc. The fifth is to return the macro name and macro value. When the lexical analyzer matches the #define and #undef keywords, save the corresponding macro name and macro value, and return the tag corresponding to the macro name and macro value: NAME, MACROVALUE, It is convenient for the subsequent parser to perform macro operations according to the matched macro name and value, for example, adding or deleting the corresponding macro definition in the macro definition manager.
步骤206,根据标记和预设的条件编译语法规则匹配出相应的事件。Step 206: Compile the corresponding event according to the markup and the preset conditional compilation grammar rule.
在本实施例中,终端中预先设置了条件编译语法规则与事件之间的对应关系,首先,根据标记匹配到某个语法规则,进而根据该匹配到的语法规则确定对应的事件,并输出对应的事件,便于后续根据事件确定相应的处理动作。其中,事件是指程序中某件事发生的信号。具体地,终端可以通过使用语法分析器根据标记和预设的条件编译语法规则匹配出相应事件的。在一个实施例中,终端首先启动语法分析器,语法分析器内部调用词法分析器,利用词法分析器输出的标记(token)和预先定义的条件编译语法规则,匹配出
相应的事件。其中,语法分析器可以采用Yacc来实现,Yacc是语法分析代码生成器,它根据定义的语法文件生成语法分析器。语法文件采用巴科斯范式(Backus-Naur Form)来描述语法规则,它使用lex输出的标记(token)以及自身定义的语法规则来匹配并执行相应的动作(比如,执行一段C代码)。如表1中所示,展示了事件与对应的条件编译语法规则的说明。In this embodiment, the correspondence between the conditional compilation grammar rules and the event is preset in the terminal. First, the tag is matched to a certain grammar rule, and then the corresponding event is determined according to the matched grammar rule, and the corresponding event is output. The event facilitates subsequent determination of the corresponding processing action based on the event. Among them, an event is a signal that something happens in a program. Specifically, the terminal can match the corresponding event by using a parser to compile the grammar rules according to the mark and the preset condition. In one embodiment, the terminal first launches a parser, and the parser internally calls a lexer that matches the tokens output by the lexer and predefined conditional compilation grammar rules.
The corresponding event. Among them, the parser can be implemented by Yacc, which is a parsing code generator that generates a parser based on the defined grammar file. The grammar file uses the Backus-Naur Form to describe the grammar rules. It uses the tokens exported by lex and its own defined grammar rules to match and execute the corresponding actions (for example, executing a piece of C code). As shown in Table 1, an illustration of the event and corresponding conditional compilation syntax rules is shown.
表1Table 1
步骤208,根据当前状态和事件确定相应的处理动作。Step 208: Determine a corresponding processing action according to the current state and the event.
在本实施例中,终端根据标记和预设的条件编译语法规则匹配出相应的事件后,获取当前状态,根据当前状态和事件确定相应的处理动作。在一个实施例中,可以预先存储处理动作与当前状态和事件的关系表,当获取到当前状态和事件后可以确定相应的处理动作,其中,处理动作可以为删除或保留某段代码。在另一个实施例中,首先需要根据当前状态和事件确定下一步的状态,继而根据下一步的状态确定对应的处理动作。具体地,首先,终端通过语法分析器匹配到事件后,输出事件到状态处理器中,驱动状态处理器中的状态进行跳转,即从一个状态跳转到另一个状态。然后根据跳转到的另
一个状态确定对应的处理动作。其中,语法分析器、状态处理器等都是终端内部的软件实现。在一个实施例中,根据条件编译语法特性,状态处理器采用栈的方式来存储和管理状态(即维护了一个状态栈)。如表2中所示,展示了预定义的状态以及相应的状态说明。通过获取当前状态和匹配到的事件确定下一步状态(参考表3),进而确定对应的处理动作。In this embodiment, after the terminal matches the corresponding event according to the mark and the preset conditional compilation grammar rule, the terminal acquires the current state, and determines a corresponding processing action according to the current state and the event. In an embodiment, a relationship table between the processing action and the current state and the event may be pre-stored, and the corresponding processing action may be determined after the current state and the event are obtained, wherein the processing action may be deleting or retaining a certain piece of code. In another embodiment, it is first necessary to determine the state of the next step based on the current state and the event, and then determine the corresponding processing action according to the state of the next step. Specifically, first, after the terminal matches the event by the parser, the event is output to the state processor, and the state in the state processor is driven to jump, that is, jump from one state to another state. Then according to the jump to another
A state determines the corresponding processing action. Among them, the parser, the state processor, etc. are all software implementations inside the terminal. In one embodiment, the state processor compiles the syntax characteristics according to conditions, and the state processor stores and manages the state in a stack (ie, maintains a state stack). As shown in Table 2, the predefined states and corresponding state descriptions are shown. The next state is determined by acquiring the current state and the matched event (refer to Table 3), and then determining the corresponding processing action.
表2Table 2
步骤210,根据确定的处理动作对原程序文本进行对应的处理,输出处理后的目标程序文本。Step 210: Perform corresponding processing on the original program text according to the determined processing action, and output the processed target program text.
在本实施例中,终端当确定完处理动作后,根据该确定的处理动作对原程序文本进行对应的处理,并输出处理后的目标程序文本,该输出的目标程序文本就是根据指定条件筛选出来的需要用到的目标程序代码,后续使用编译器对该目标程序文本进行编译即可实现对应的条件编译功能。具体地,终端通过状态处理器根据下一步状态向动作处理器的动作列表中添加相应的处理动作,然后动作处理器会根据动作列表中的处理动作进行对应的处理,比如,删除相应的一行或多行代码,之后输出处理后的目标程序文本,其中,状态处理器、动作处理器是终端内部的软件实现,可以理解为功能实现模块。In this embodiment, after determining the processing action, the terminal performs corresponding processing on the original program text according to the determined processing action, and outputs the processed target program text, and the output target program text is filtered according to the specified condition. The target program code that needs to be used, and then compile the target program text by using the compiler to implement the corresponding conditional compilation function. Specifically, the terminal adds a corresponding processing action to the motion processor's action list according to the next state by the state processor, and then the action processor performs corresponding processing according to the processing action in the action list, for example, deleting the corresponding row or The multi-line code, after which the processed target program text is output, wherein the state processor and the action processor are software implementations inside the terminal, which can be understood as a function implementation module.
在本实施例中,通过对原程序文本进行分析,根据预设的正则表达式匹配出对应的关键字并输出相应的标记,然后根据标记和预设的条件编译语法规则匹配出相应的事件,根据当前状态和事件确定相应的处理动作,然后根据确定的处理动作对原程序文本进行对应的处理,输出处理后的目标程序文本。该方法通过模拟条件编译的过程对原程序文本进行条件编译预处理,使得使用解释型语言开发时仍然可以使用条件编译特性,当需要适用多种配置时,通过使用该条件编译预处理方法不仅减少了维护成本,而且减少了资源
消耗。In this embodiment, by analyzing the original program text, matching the corresponding keyword according to the preset regular expression and outputting the corresponding mark, and then compiling the corresponding event according to the mark and the preset condition compiling the grammar rule, The corresponding processing action is determined according to the current state and the event, and then the original program text is processed correspondingly according to the determined processing action, and the processed target program text is output. This method preconditions the conditional compilation of the original program text by simulating the conditional compilation process, so that the conditional compilation feature can still be used when developing the interpreted language. When multiple configurations are required, the pre-compilation method is not reduced by using the condition. Maintenance costs and reduced resources
Consumption.
如图3所示,在一个实施例中,根据当前状态和事件确定相应的处理动作的步骤包括:As shown in FIG. 3, in one embodiment, the steps of determining a corresponding processing action based on the current state and the event include:
步骤208A,根据当前状态和事件确定下一步状态。In step 208A, the next state is determined according to the current state and the event.
在本实施例中,当根据预设的条件编译语法规则匹配到相应的事件后,获取当前状态,通过查询状态表查找与当前状态和事件对应的下一步状态。如表3中所示,为一个实施例中的状态表。表3中纵轴第1列代表的是当前状态,横轴第1行为事件,其他单元格表示当前状态接收到事件时的下一步状态。比如,当前状态为初始态,即STATE_INITIAL,而发生的事件为EVENT_IF_TRUE,通过查询状态表,即表3,可以得到对应的下一步状态为STATE_IF_TRUE(即第3行第2列对应的单元格)。In this embodiment, after the compiled grammar rules are matched to the corresponding events according to the preset conditions, the current state is obtained, and the next state corresponding to the current state and the event is searched by querying the state table. As shown in Table 3, it is a state table in one embodiment. In column 3, the first column of the vertical axis represents the current state, the horizontal axis is the first behavior event, and the other cells indicate the next state when the current state receives the event. For example, the current state is the initial state, that is, STATE_INITIAL, and the event that occurs is EVENT_IF_TRUE. By querying the state table, that is, Table 3, the corresponding next state is STATE_IF_TRUE (ie, the cell corresponding to the third row and the second column).
表3table 3
步骤208B,根据下一步状态确定相应的处理动作。In step 208B, the corresponding processing action is determined according to the next state.
在本实施例中,当确定了下一步状态后,根据该下一步状态确定相应的处理动作。具体地,根据下一步的状态,可以区分出下一步采取的动作。预先定义动作的类型,比如,动作分为两类,一种是删除当前行(比如,if,else,elif自己所在行),对应的下一步状态为:STATE_IF_TRUE,STATE_ELSE_TRUE,STATE_ELIF_TRUE,STATE_ENDIF;一种是删除多行,对应的下一步状态为:STATE_IF_FALSE,STATE_IF_INHERIT_FALSE,STATE_ELSE_FALSE,STATE_ELIF_FALSE。In this embodiment, after the next state is determined, the corresponding processing action is determined according to the next state. Specifically, according to the state of the next step, the action taken in the next step can be distinguished. Pre-defined types of actions, for example, actions are divided into two categories, one is to delete the current line (for example, if, else, elif their own line), the corresponding next state is: STATE_IF_TRUE, STATE_ELSE_TRUE, STATE_ELIF_TRUE, STATE_ENDIF; Is to delete multiple rows, the corresponding next state is: STATE_IF_FALSE, STATE_IF_INHERIT_FALSE, STATE_ELSE_FALSE, STATE_ELIF_FALSE.
如图4所示,在一个实施例中,根据确定的处理动作对原程序文本进行对应的处理,输出处理后的目标程序文本的步骤包括:As shown in FIG. 4, in an embodiment, the original program text is processed correspondingly according to the determined processing action, and the step of outputting the processed target program text includes:
步骤210A,将确定的处理动作添加到动作列表。 Step 210A, adding the determined processing action to the action list.
在本实施例中,根据当前状态和事件确定相应的处理动作后,将确定的动作添加到动作列表。具体地,终端首先通过语法分析器匹配到事件,然后由该事件驱动状态处理器的跳转,之后状态处理器通过查询状态表根据当前状态和事件确定下一步状态,然后根据下一步状态确定对应的处理动作,进而将确定的动作添加到动作处理器的动作列表,便于后续动作处理器根据动作列表中的动作进行相应的处理,其中,语法分析器、状态处理器、动作处理器等都是终端内部的软件实现。In this embodiment, after determining the corresponding processing action according to the current state and the event, the determined action is added to the action list. Specifically, the terminal first matches the event by the parser, and then the event drives the jump of the state processor, after which the state processor determines the next state according to the current state and the event by querying the state table, and then determines the corresponding according to the next state. The processing action, and then the determined action is added to the action list of the action processor, so that the subsequent action processor performs corresponding processing according to the action in the action list, wherein the parser, the state processor, the action processor, etc. are all Software implementation inside the terminal.
步骤210B,根据动作列表对原程序文本执行对应的处理动作,输出处理后的目标程序文本。 Step 210B: Perform a corresponding processing operation on the original program text according to the action list, and output the processed target program text.
在本实施例中,终端通过状态处理器将处理动作添加到动作处理器的动
作列表后,根据动作列表对原程序文件进行处理的方式有两种,一种是,将所有的处理动作都添加到动作列表后,动作处理器根据保存的一系列处理动作对原程序文本执行对应的操作;一种是,每当有动作添加到动作列表,动作处理器便开始执行对应的处理动作,然后输出处理后的程序文本,即目标程序文本。举个例子,根据典型的条件编译处理#if true...#else...#endif,最终采取的处理动作为1)删除#if true这一行本身;2)删除#else(含)到endif(含)之间的所有行。考虑到待删除的代码本身对程序员有参考价值,动作处理器并不真正删除代码行,而是在这些代码前加上行注释“//”。终端完成处理动作后,输出处理后的目标程序文本,如果后面还有编译过程,则输出到编译器进行处理,从而实现了条件编译。In this embodiment, the terminal adds the processing action to the motion processor through the state processor.
After the list is made, there are two ways to process the original program file according to the action list. One is that after all the processing actions are added to the action list, the action processor executes the original program text according to the saved series of processing actions. Corresponding operation; one is that whenever an action is added to the action list, the action processor starts executing the corresponding processing action, and then outputs the processed program text, that is, the target program text. For example, according to the typical conditional compilation process #if true...#else...#endif, the final processing action is 1) delete the #if true line itself; 2) delete #else() to the endif All lines between (inclusive). Considering that the code to be deleted itself has a reference value to the programmer, the action processor does not actually delete the line of code, but adds a line comment "//" before the code. After the terminal completes the processing action, the processed target program text is output. If there is a compiling process later, the output is output to the compiler for processing, thereby implementing conditional compilation.
在一个实施例中,根据标记和预设的条件编译语法规则匹配出相应的事件的步骤包括:根据标记和预设的条件编译语法规则进行匹配,当匹配到包含宏名称的条件语句时,向宏定义管理器查询与宏名称对应的定义及相应的值以进行条件判断,根据条件判断的结果匹配出相应的事件。In one embodiment, the step of compiling the corresponding event according to the markup and the preset conditional compilation grammar rule comprises: matching the grammar rule according to the mark and the preset condition, and when matching the conditional statement containing the macro name, The macro definition manager queries the definition corresponding to the macro name and the corresponding value for conditional judgment, and matches the corresponding event according to the result of the conditional judgment.
在本实施例中,宏定义管理器用于管理宏定义,条件编译的条件判断有时需要基于宏定义的内容。当匹配到包含宏名称的条件语句时,需要向宏定义管理器中查询与匹配到的宏名称对应的宏值,便于根据该宏值进行条件判断,即判断该条件是TRUE还是FALSE。其中,宏定义包含两大类,一种是通过命令行参数传入的全局宏定义-D,一种是文件局部使用#define定义的宏。局部定义的宏会覆盖全局定义,而且只会影响本文件该行后面的行为,对其他文件不产生作用。另外,宏记录的信息除了包括宏类型,即全局宏和局部宏外,还记录了宏的状态、宏名称、宏值以及宏行号。宏状态包括可用的、暂时失效的、无效的。其中,暂时失效状态适用于全局宏,表示使用-D定义过但是在某个文件中被取消(#undef)了,这个状态只影响该文件本身,处理另一个文件时,-D仍然恢复为可用状态;无效状态适用于局部宏,表示在某个文件中被取消(#undef)了。宏定义管理器中的宏行号仅对局部宏有效,它主要用于当检测到同一文件中出现两次相同的宏定义时,给出警告,提示
当前的定义在哪一行,在做查询操作时,先检测局部宏,如果不存在,在检查全局宏。在一个实施例中,当碰到以下语句#ifdef NAME,#ifndef NAME,#if NAME,#elif NAME,#if defined(NAME)时,需要查询宏定义管理器,看是否定义以及对应的值是什么,如果查找不到,则返回NULL表示找不到定义。In the present embodiment, the macro definition manager is used to manage the macro definition, and the conditional judgment of the conditional compilation sometimes requires content based on the macro definition. When matching the conditional statement containing the macro name, it is necessary to query the macro definition manager for the macro value corresponding to the matched macro name, so as to facilitate the conditional judgment according to the macro value, that is, whether the condition is TRUE or FALSE. Among them, the macro definition contains two major categories, one is the global macro definition -D passed in through the command line parameters, and the other is the macro defined by the file #define. A locally defined macro overrides the global definition and only affects the behavior behind the line in this file, and has no effect on other files. In addition, the information of the macro record records the state of the macro, the macro name, the macro value, and the macro line number in addition to the macro type, that is, the global macro and the local macro. Macro states include available, temporarily disabled, and invalid. Among them, the temporary invalid state applies to the global macro, which means that it is defined with -D but is canceled in a file (#undef). This state only affects the file itself. When another file is processed, -D is still restored. State; invalid state applies to local macros, indicating that they are canceled (#undef) in a file. The macro line number in the macro definition manager is only valid for local macros. It is mainly used to give a warning when the same macro definition is found twice in the same file.
The current definition is in which row. When doing the query operation, the local macro is detected first. If it does not exist, the global macro is checked. In one embodiment, when the following statement #ifdef NAME, #ifndef NAME, #if NAME, #elif NAME, #if defined(NAME) is encountered, the macro definition manager needs to be queried to see if the definition and the corresponding value are What, if not found, returns NULL to indicate that the definition could not be found.
在一个实施例中,当匹配到包含宏名称的定义语句时,根据定义语句的类型在宏定义管理器中增加或删除相应的宏定义。In one embodiment, when a definition statement containing a macro name is matched, the corresponding macro definition is added or deleted in the macro definition manager according to the type of the definition statement.
在本实施例中,由于有时进行条件判断需要基于宏定义管理器中的宏定义,所以首先需要在宏定义管理器中添加宏定义,添加后如果在后面发现被取消了,还需要在宏定义管理器中删除相应的宏定义。具体地,首先是终端通过词法分析器根据预设的正则表达式进行匹配,并输出相应的标记,其中,标记中包含了代表宏名称的标记。比如,当匹配到关键字#define NAME VALUE、#define NAME或#undef NAME时,返回宏的名称。也就是说,当匹配到define,undef关键字时,将对应的文本存储(将真实的宏名称存储),并返回标记NAME。然后通过语法分析器根据标记和预设的条件编译语法规则进行匹配,当匹配到包含宏名称的定义语句时,则根据该定义语句的类型在宏定义管理器中增加或删除相应的宏定义。其中,宏定义语句是指包含#define,#undef等定义性词语的语句。根据定义语句的类型,将语句分为定义和取消定义两种,其中,包含#define的语句表示定义类型的语句,包含#undef的语句表示取消定义类型的语句。在一个实施例中,当碰到以下语句时对宏定义管理器进行添加操作#define NAME,#define NAME VALUE,当碰到#undef NAME时会对宏定义管理器进行删除操作。通过在宏定义管理器中添加或删除宏定义,便于后续当匹配到含有宏名称的条件语句时,通过查询相应的宏定义来进行条件判断,即判断是TRUE还是FALSE。In this embodiment, since the condition determination needs to be based on the macro definition in the macro definition manager, it is first necessary to add a macro definition in the macro definition manager, and if it is found later, it is also required to be in the macro definition. The corresponding macro definition is removed from the manager. Specifically, first, the terminal performs matching according to a preset regular expression by the lexical analyzer, and outputs a corresponding mark, wherein the mark includes a mark representing a macro name. For example, when matching the keyword #define NAME VALUE, #define NAME, or #undef NAME, the name of the macro is returned. That is, when matching the define, undef keyword, the corresponding text is stored (the real macro name is stored) and the tag NAME is returned. Then, the parser performs matching according to the markup and the preset conditional compilation grammar rule. When it matches the definition statement containing the macro name, the corresponding macro definition is added or deleted in the macro definition manager according to the type of the definition statement. Among them, the macro definition statement refers to a statement containing definition words such as #define, #undef. According to the type of the definition statement, the statement is divided into two types: definition and undefine. The statement containing #define represents the statement of the defined type, and the statement containing #undef represents the statement of the undefined type. In one embodiment, the macro definition manager is added to the macro definition manager when it encounters the following statement #define NAME, #define NAME VALUE, and the macro definition manager is deleted when it encounters #undef NAME. By adding or deleting a macro definition in the macro definition manager, it is convenient to subsequently perform conditional judgment by querying the corresponding macro definition when matching to a conditional statement containing a macro name, that is, whether it is TRUE or FALSE.
在一个实施例中,对原程序文本进行分析,根据预设的正则表达式匹配出对应的关键字并输出相应的标记的步骤204包括:对原程序文本进行分析,根据预设的正则表达式匹配出对应的关键字,记录关键字所在的行号,输出
相应的标记和对应的行号。In one embodiment, the step of analyzing the original program text, matching the corresponding keyword according to the preset regular expression and outputting the corresponding mark includes: analyzing the original program text according to the preset regular expression Match the corresponding keyword, record the line number where the keyword is located, and output
The corresponding tag and the corresponding line number.
在本实施例中,为了便于执行确定的处理动作,在对原程序文本进行分析,匹配出对应的关键字后,不仅需要输出与关键字对应的标记(token),而且需要记录每个匹配到的关键字所在的行号并输出。记录行号对后续的处理非常重要,因为动作处理器最终是依赖行号对程序文本进行处理的。具体实现的手段可以通过定义一个用于增加行号的c函数,然后由词法分析器通过调用这个函数来增加全局行号。比如,每当碰到“\n”时,调用c函数增加全局行号。In this embodiment, in order to facilitate the execution of the determined processing action, after analyzing the original program text and matching the corresponding keywords, not only the token corresponding to the keyword needs to be output, but also each matching is required to be recorded. The line number of the keyword is output and output. Recording the line number is very important for subsequent processing because the action processor ultimately relies on the line number to process the program text. The specific implementation means that by adding a c function for increasing the line number, the lexical analyzer then calls the function to increase the global line number. For example, whenever you encounter "\n", call the c function to increase the global line number.
在一个实施例中,根据确定的处理动作对原程序文本进行对应的处理,输出处理后的目标程序文本的步骤210包括:根据处理动作的类型和对应的行号执行对应的处理动作,输出处理后的目标程序文本。In an embodiment, the processing of the original program text is performed according to the determined processing action, and the step 210 of outputting the processed target program text includes: performing a corresponding processing action according to the type of the processing action and the corresponding line number, and outputting the processing After the target program text.
在本实施例中,终端通过状态处理器将对应的处理动作添加到动作处理器的动作列表后,使动作处理器根据处理动作的类型和对应的行号执行对应的处理动作,然后输出处理后的目标程序文本。处理动作的类型可以分为两类:一种是删除当前行;一种是删除多行。在进行动作处理时,每个处理动作都对应一个起始行号和结束行号信息。第I类动作可以当成起始行号和结束行号相同的特例。对于第II类动作,由于在匹配到删除多行的事件时,还不知道结束行号是多少,可以暂时将结束行号与起始行号写成相同的值,当下一个事件产生新的动作后,在添加新动作之前,将之前的结束行号更新为当前行号-1即可。具体地,处理动作是与状态处理器确定的下一步状态对应的,当下一步状态为:STATE_IF_TRUE,STATE_ELSE_TRUE,STATE_ELIF_TRUE,STATE_ENDIF时,则对应的动作为:删除当前行。当下一步状态为:STATE_IF_FALSE,STATE_IF_INHERIT_FALSE,STATE_ELSE_FALSE,STATE_ELIF_FALSE时,对应的动作为:删除多行。举例说明,当确定的下一步状态为STATE_IF_TRUE时,那么只需要删除当前行,即起始行号和结束行号相同。当确定的下一步状态为:STATE_IF_FALSE时,说明需要删除多行,但是具体删除几行还不知道,即
还不知道结束行号是多少,当出现下一个事件时,假设出现的新事件为EVENT_ELSE_TRUE,那么其对应的下一个状态为STATE_ELSE_TRUE,表示删除当前行,在删除当前行之前,将当前行号减去1,作为上一事件的结束行号。In this embodiment, after the terminal adds the corresponding processing action to the action list of the action processor by the state processor, the action processor executes the corresponding processing action according to the type of the processing action and the corresponding line number, and then outputs the processed process. Target program text. The types of processing actions can be divided into two categories: one is to delete the current row; the other is to delete multiple rows. When the action processing is performed, each processing action corresponds to a start line number and an end line number information. The first type of action can be treated as a special case with the same starting line number and ending line number. For the second type of action, since it is not known what the ending line number is when matching the event of deleting multiple lines, the ending line number and the starting line number can be temporarily written to the same value, when the next event generates a new action. , before adding a new action, update the previous end line number to the current line number -1. Specifically, the processing action is corresponding to the next state determined by the state processor. When the next state is: STATE_IF_TRUE, STATE_ELSE_TRUE, STATE_ELIF_TRUE, STATE_ENDIF, the corresponding action is: deleting the current row. When the next state is: STATE_IF_FALSE, STATE_IF_INHERIT_FALSE, STATE_ELSE_FALSE, STATE_ELIF_FALSE, the corresponding action is: delete multiple rows. For example, when the determined next state is STATE_IF_TRUE, then only the current row needs to be deleted, that is, the starting row number and the ending row number are the same. When the determined next state is: STATE_IF_FALSE, it means that multiple rows need to be deleted, but it is not known to delete a few rows, that is,
I don't know what the ending line number is. When the next event occurs, assuming that the new event is EVENT_ELSE_TRUE, then the corresponding next state is STATE_ELSE_TRUE, indicating that the current line is deleted, and the current line number is reduced before deleting the current line. Go to 1, as the end line number of the previous event.
如图5所示,在一个实施例中,实现上述条件编译的方法具体是通过词法分析器、语法分析器、状态处理器、动作处理器以及宏定义管理器相互配合来完成的。首先,如果命令行参数中有-D,主程序会将全局宏添加到宏定义管理器中,接下来,终端中的主程序对每个原程序文本,循环执行如下操作,a),主程序启用语法分析器,语法分析器内部调用词法分析器,通过词法分析器对原程序文本进行分析匹配出相应的关键字并输出相应的标记(token),然后语法分析器利用词法分析器输出的标记(token)及事先定义的语法规则,产生相应的事件,在此过程中,根据匹配到的包含宏名称的语句对宏定义管理器进行相应的增、删、查的操作;b)语法分析器输出事件到状态处理器,驱动状态机的跳转,状态处理器根据下一步状态确定相应的处理动作,并将处理动作添加到动作处理器中。c)主程序按顺序执行处理器中的动作列表,输出处理后的程序文本,即目标程序文本。上述词法分析器、语法分析器、状态处理器、动作处理器以及宏定义管理器通过相互配合实现了对条件编译的预处理,实现该条件编译的预处理方法所对应的条件编译预处理器的执行文件仅36k左右,是一种轻量级的条件编译预处理器,且如果有后续编译过程,只需在标准编译流程前添加条件编译预处理器命令即可,方便集成。此外,该方法适用于多种语言,比如,WMLScript,JavaScript,Java、Python等,由于不同程序语言有不同的规范,可根据需要微调词法、语法规则文件就可以快速适应任何语言。因此,还具有通用性,易扩展的特点。As shown in FIG. 5, in one embodiment, the method for implementing the above conditional compilation is specifically performed by a lexical analyzer, a parser, a state processor, an action processor, and a macro definition manager. First, if there is -D in the command line parameter, the main program will add the global macro to the macro definition manager. Next, the main program in the terminal performs the following operations on each original program text, a), the main program Enable the parser, the parser internally calls the lexical analyzer, analyzes the original program text through the lexical analyzer to match the corresponding keyword and outputs the corresponding token, and then the parser uses the token output by the lexical analyzer. (token) and pre-defined grammar rules, corresponding events are generated. In the process, the macro definition manager is added, deleted, and checked according to the matched statement containing the macro name; b) the parser The event is output to the state processor, which drives the jump of the state machine. The state processor determines the corresponding processing action according to the next state, and adds the processing action to the action processor. c) The main program executes the action list in the processor in order, and outputs the processed program text, that is, the target program text. The lexical analyzer, the parser, the state processor, the action processor and the macro definition manager respectively implement preprocessing of the conditional compilation by mutual cooperation, and implement the conditional compiling preprocessor corresponding to the preprocessing method of the conditional compilation. The execution file is only about 36k. It is a lightweight conditional compilation preprocessor. If there is a subsequent compilation process, you only need to add the conditional compilation preprocessor command before the standard compilation process to facilitate integration. In addition, the method is applicable to multiple languages, such as WMLScript, JavaScript, Java, Python, etc. Since different programming languages have different specifications, you can quickly adapt to any language by fine-tuning lexical and grammatical rules files as needed. Therefore, it is also versatile and easy to expand.
本申请实施例提供了一种终端,终端的内部结构可对应于如图1所示的结构,下述每个模块可全部或部分通过软件、硬件或其组合来实现。The embodiment of the present application provides a terminal. The internal structure of the terminal may correspond to the structure shown in FIG. 1. Each of the following modules may be implemented in whole or in part by software, hardware, or a combination thereof.
在一个实施例中,如图6所示,该实施例中的终端600包括:In an embodiment, as shown in FIG. 6, the terminal 600 in this embodiment includes:
获取模块602,用于获取待处理的原程序文本。
The obtaining module 602 is configured to obtain the original program text to be processed.
输出模块604,用于对原程序文本进行分析,根据预设的正则表达式匹配出对应的关键字并输出相应的标记。The output module 604 is configured to analyze the original program text, match the corresponding keyword according to the preset regular expression, and output a corresponding mark.
匹配模块606,用于根据标记和预设的条件编译语法规则匹配出相应的事件。The matching module 606 is configured to match the corresponding event according to the markup and the preset conditional compilation grammar rule.
确定模块608,用于根据当前状态和事件确定相应的处理动作。The determining module 608 is configured to determine a corresponding processing action according to the current state and the event.
处理模块610,用于根据确定的处理动作对原程序文本进行对应的处理,输出处理后的目标程序文本。The processing module 610 is configured to perform corresponding processing on the original program text according to the determined processing action, and output the processed target program text.
在一个实施例中,确定模块还用于根据当前状态和事件确定下一步状态,根据下一步状态确定相应的处理动作。In an embodiment, the determining module is further configured to determine a next state according to the current state and the event, and determine a corresponding processing action according to the next state.
在一个实施例中,处理模块还用于将确定的处理动作添加到动作列表,根据动作列表对原程序文本执行对应的处理动作,输出处理后的目标程序文本。In one embodiment, the processing module is further configured to add the determined processing action to the action list, perform a corresponding processing action on the original program text according to the action list, and output the processed target program text.
在一个实施例中,匹配模块还用于根据标记和预设的条件编译语法规则进行匹配,当匹配到包含宏名称的条件语句时,向宏定义管理器查询与宏名称对应的定义及相应的值以进行条件判断,根据条件判断的结果匹配出相应的事件。In an embodiment, the matching module is further configured to perform matching according to the markup and the preset conditional compilation grammar rule, and when matching the conditional statement containing the macro name, query the macro definition manager to query the definition corresponding to the macro name and corresponding The value is judged by the condition, and the corresponding event is matched according to the result of the conditional judgment.
在一个实施例中,输出模块还用于对原程序文本进行分析,根据预设的正则表达式匹配出对应的关键字,记录关键字所在的行号,输出相应的标记和对应的行号。处理模块还用于根据处理动作的类型和对应的行号执行对应的处理动作,输出处理后的目标程序文本。In an embodiment, the output module is further configured to analyze the original program text, match the corresponding keyword according to the preset regular expression, record the line number where the keyword is located, and output the corresponding mark and the corresponding line number. The processing module is further configured to execute a corresponding processing action according to the type of the processing action and the corresponding line number, and output the processed target program text.
本领域普通技术人员可以理解实现上述实施例方法中的全部或部分流程,是可以通过计算机程序来指令相关的硬件来完成,该计算机程序可存储于一计算机可读取存储介质中,该程序在执行时,可包括如上述各方法的实施例的流程。其中,前述的存储介质可为磁碟、光盘、只读存储记忆体(Read-Only Memory,ROM)等非易失性存储介质,或随机存储记忆体(Random Access Memory,RAM)等。
A person skilled in the art can understand that all or part of the process of implementing the above embodiment method can be completed by a computer program to instruct related hardware, and the computer program can be stored in a computer readable storage medium. When executed, the flow of an embodiment of the methods as described above may be included. The storage medium may be a non-volatile storage medium such as a magnetic disk, an optical disk, a read-only memory (ROM), or a random access memory (RAM).
以上所述实施例的各技术特征可以进行任意的组合,为使描述简洁,未对上述实施例中的各个技术特征所有可能的组合都进行描述,然而,只要这些技术特征的组合不存在矛盾,都应当认为是本说明书记载的范围。The technical features of the above-described embodiments may be arbitrarily combined. For the sake of brevity of description, all possible combinations of the technical features in the above embodiments are not described. However, as long as there is no contradiction between the combinations of these technical features, All should be considered as the scope of this manual.
以上所述实施例仅表达了本申请的几种实施方式,其描述较为具体和详细,但并不能因此而理解为对申请专利范围的限制。应当指出的是,对于本领域的普通技术人员来说,在不脱离本申请构思的前提下,还可以做出若干变形和改进,这些都属于本申请的保护范围。因此,本申请专利的保护范围应以所附权利要求为准。
The above-mentioned embodiments are merely illustrative of several embodiments of the present application, and the description thereof is more specific and detailed, but is not to be construed as limiting the scope of the claims. It should be noted that a number of variations and modifications may be made by those skilled in the art without departing from the spirit and scope of the present application. Therefore, the scope of the invention should be determined by the appended claims.
Claims (15)
- 一种条件编译预处理方法,包括:A conditional compilation preprocessing method, including:获取待处理的原程序文本;Obtain the original program text to be processed;对所述原程序文本进行分析,根据预设的正则表达式匹配出对应的关键字,输出与所述关键字相应的标记;Parsing the original program text, matching corresponding keywords according to a preset regular expression, and outputting a mark corresponding to the keyword;根据所述标记和预设的条件编译语法规则匹配出相应的事件;Compiling the corresponding event according to the mark and the preset conditional compilation grammar rule;根据当前状态和所述事件确定相应的处理动作;及Determining corresponding processing actions according to the current state and the event; and根据确定的所述处理动作对所述原程序文本进行对应的处理,输出处理后的目标程序文本。The original program text is processed correspondingly according to the determined processing action, and the processed target program text is output.
- 根据权利要求1所述的方法,其特征在于,所述根据当前状态和所述事件确定相应的处理动作包括:The method according to claim 1, wherein the determining the corresponding processing action according to the current state and the event comprises:根据当前状态和所述事件确定下一步状态;Determining a next state based on the current state and the event;根据所述下一步状态确定相应的处理动作。Corresponding processing actions are determined according to the next state.
- 根据权利要求1所述的方法,其特征在于,所述根据确定的所述处理动作对所述原程序文本进行对应的处理,输出处理后的目标程序文本包括:The method according to claim 1, wherein the processing of the original program text according to the determined processing action, and outputting the processed target program text comprises:将确定的所述处理动作添加到动作列表;Adding the determined processing action to the action list;根据所述动作列表对所述原程序文本执行对应的处理动作,输出处理后的目标程序文本。Performing a corresponding processing operation on the original program text according to the action list, and outputting the processed target program text.
- 根据权利要求1所述的方法,其特征在于,所述根据所述标记和预设的条件编译语法规则匹配出相应的事件包括:The method according to claim 1, wherein the matching the corresponding event according to the mark and the preset conditional compilation grammar rule comprises:根据所述标记和预设的条件编译语法规则进行匹配,当匹配到包含宏名称的条件语句时,向宏定义管理器查询与所述宏名称对应的定义及相应的值以进行条件判断,根据所述条件判断的结果匹配出相应的事件。Matching according to the mark and the preset conditional compilation grammar rule, when matching the conditional statement containing the macro name, querying the macro definition manager for the definition corresponding to the macro name and the corresponding value for conditional judgment, according to The result of the conditional judgment matches the corresponding event.
- 根据权利要求1所述的方法,其特征在于,所述对所述原程序文本进行分析,根据预设的正则表达式匹配出对应的关键字并输出相应的标记包括:The method according to claim 1, wherein the analyzing the original program text, matching corresponding keywords according to a preset regular expression, and outputting corresponding tags include:对所述原程序文本进行分析,根据预设的正则表达式匹配出对应的关键字,记录所述关键字所在的行号,输出相应的标记和对应的行号; Parsing the original program text, matching the corresponding keyword according to the preset regular expression, recording the line number where the keyword is located, and outputting the corresponding mark and the corresponding line number;所述根据确定的所述处理动作对所述原程序文本进行对应的处理,输出处理后的目标程序文本包括:Performing corresponding processing on the original program text according to the determined processing action, and outputting the processed target program text includes:根据所述处理动作的类型和对应的行号执行对应的处理动作,输出处理后的目标程序文本。The corresponding processing operation is executed according to the type of the processing operation and the corresponding line number, and the processed target program text is output.
- 一种终端,包括存储器和处理器,所述存储器中储存有计算机可读指令,所述计算机可读指令被所述处理器执行时,使得所述处理器执行以下步骤:A terminal comprising a memory and a processor, the memory storing computer readable instructions, the computer readable instructions being executed by the processor such that the processor performs the following steps:获取待处理的原程序文本;Obtain the original program text to be processed;对所述原程序文本进行分析,根据预设的正则表达式匹配出对应的关键字,输出与所述关键字相应的标记;Parsing the original program text, matching corresponding keywords according to a preset regular expression, and outputting a mark corresponding to the keyword;根据所述标记和预设的条件编译语法规则匹配出相应的事件;Compiling the corresponding event according to the mark and the preset conditional compilation grammar rule;根据当前状态和所述事件确定相应的处理动作;及Determining corresponding processing actions according to the current state and the event; and根据确定的所述处理动作对所述原程序文本进行对应的处理,输出处理后的目标程序文本。The original program text is processed correspondingly according to the determined processing action, and the processed target program text is output.
- 根据权利要求6所述的终端,其特征在于,所述处理器所执行的根据当前状态和所述事件确定相应的处理动作包括:根据当前状态和所述事件确定下一步状态,根据所述下一步状态确定相应的处理动作。The terminal according to claim 6, wherein the determining, by the processor, the corresponding processing action according to the current state and the event comprises: determining a next state according to the current state and the event, according to the next The one-step state determines the corresponding processing action.
- 根据权利要求6所述的终端,其特征在于,所述处理器所执行的根据确定的所述处理动作对所述原程序文本进行对应的处理,输出处理后的目标程序文本包括:将确定的所述处理动作添加到动作列表,根据所述动作列表对所述原程序文本执行对应的处理动作,输出处理后的目标程序文本。The terminal according to claim 6, wherein the processor performs corresponding processing on the original program text according to the determined processing action, and outputting the processed target program text comprises: determining The processing operation is added to the action list, and a corresponding processing operation is performed on the original program text according to the action list, and the processed target program text is output.
- 根据权利要求6所述的终端,其特征在于,所述处理器所执行的根据所述标记和预设的条件编译语法规则匹配出相应的事件包括:根据所述标记和预设的条件编译语法规则进行匹配,当匹配到包含宏名称的条件语句时,向宏定义管理器查询与所述宏名称对应的定义及相应的值以进行条件判断,根据所述条件判断的结果匹配出相应的事件。 The terminal according to claim 6, wherein the matching of the corresponding event by the processor according to the mark and the preset conditional compilation grammar rule comprises: compiling the grammar according to the mark and the preset condition The rule is matched. When the conditional statement containing the macro name is matched, the macro definition manager queries the definition corresponding to the macro name and the corresponding value to perform conditional judgment, and the result according to the condition judgment matches the corresponding event. .
- 根据权利要求6所述的终端,其特征在于,所述处理器所执行的对所述原程序文本进行分析,根据预设的正则表达式匹配出对应的关键字并输出相应的标记包括:The terminal according to claim 6, wherein the analyzing, by the processor, the original program text, matching corresponding keywords according to a preset regular expression, and outputting corresponding tags includes:对所述原程序文本进行分析,根据预设的正则表达式匹配出对应的关键字,记录所述关键字所在的行号,输出相应的标记和对应的行号;Parsing the original program text, matching the corresponding keyword according to the preset regular expression, recording the line number where the keyword is located, and outputting the corresponding mark and the corresponding line number;所述处理器所执行的根据确定的所述处理动作对所述原程序文本进行对应的处理,输出处理后的目标程序文本包括:根据所述处理动作的类型和对应的行号执行对应的处理动作,输出处理后的目标程序文本。Performing corresponding processing on the original program text according to the determined processing action performed by the processor, and outputting the processed target program text includes: performing corresponding processing according to the type of the processing action and the corresponding line number Action, output the processed target program text.
- 一个或多个存储有计算机可读指令的计算机可读非易失性存储介质,所述计算机可读指令被一个或多个处理器执行时,使得所述一个或多个处理器执行以下步骤:One or more computer readable non-volatile storage media storing computer readable instructions, when executed by one or more processors, cause the one or more processors to perform the steps of:获取待处理的原程序文本;Obtain the original program text to be processed;对所述原程序文本进行分析,根据预设的正则表达式匹配出对应的关键字,输出与所述关键字相应的标记;Parsing the original program text, matching corresponding keywords according to a preset regular expression, and outputting a mark corresponding to the keyword;根据所述标记和预设的条件编译语法规则匹配出相应的事件;Compiling the corresponding event according to the mark and the preset conditional compilation grammar rule;根据当前状态和所述事件确定相应的处理动作;及Determining corresponding processing actions according to the current state and the event; and根据确定的所述处理动作对所述原程序文本进行对应的处理,输出处理后的目标程序文本。The original program text is processed correspondingly according to the determined processing action, and the processed target program text is output.
- 根据权利要求11所述的存储介质,其特征在于,所述处理器所执行的所述根据当前状态和所述事件确定相应的处理动作包括:The storage medium according to claim 11, wherein the determining, by the processor, the corresponding processing action according to the current state and the event comprises:根据当前状态和所述事件确定下一步状态;Determining a next state based on the current state and the event;根据所述下一步状态确定相应的处理动作。Corresponding processing actions are determined according to the next state.
- 根据权利要求11所述的存储介质,其特征在于,所述处理器所执行的根据确定的所述处理动作对所述原程序文本进行对应的处理,输出处理后的目标程序文本包括:The storage medium according to claim 11, wherein the processor performs corresponding processing on the original program text according to the determined processing action, and outputting the processed target program text comprises:将确定的所述处理动作添加到动作列表;Adding the determined processing action to the action list;根据所述动作列表对所述原程序文本执行对应的处理动作,输出处理后 的目标程序文本。Performing a corresponding processing action on the original program text according to the action list, and outputting the processing Target program text.
- 根据权利要求11所述的存储介质,其特征在于,所述处理器所执行的所述根据所述标记和预设的条件编译语法规则匹配出相应的事件包括:The storage medium according to claim 11, wherein the matching, by the processor, the matching of the corresponding event according to the markup and the preset conditional compilation grammar rule comprises:根据所述标记和预设的条件编译语法规则进行匹配,当匹配到包含宏名称的条件语句时,向宏定义管理器查询与所述宏名称对应的定义及相应的值以进行条件判断,根据所述条件判断的结果匹配出相应的事件。Matching according to the mark and the preset conditional compilation grammar rule, when matching the conditional statement containing the macro name, querying the macro definition manager for the definition corresponding to the macro name and the corresponding value for conditional judgment, according to The result of the conditional judgment matches the corresponding event.
- 根据权利要求11所述的存储介质,其特征在于,所述处理器所执行的所述对所述原程序文本进行分析,根据预设的正则表达式匹配出对应的关键字并输出相应的标记包括:The storage medium according to claim 11, wherein the processor performs the analysis on the original program text, matches a corresponding keyword according to a preset regular expression, and outputs a corresponding mark. include:对所述原程序文本进行分析,根据预设的正则表达式匹配出对应的关键字,记录所述关键字所在的行号,输出相应的标记和对应的行号;Parsing the original program text, matching the corresponding keyword according to the preset regular expression, recording the line number where the keyword is located, and outputting the corresponding mark and the corresponding line number;所述处理器所执行的根据确定的所述处理动作对所述原程序文本进行对应的处理,输出处理后的目标程序文本包括:Performing corresponding processing on the original program text according to the determined processing action performed by the processor, and outputting the processed target program text includes:根据所述处理动作的类型和对应的行号执行对应的处理动作,输出处理后的目标程序文本。 The corresponding processing operation is executed according to the type of the processing operation and the corresponding line number, and the processed target program text is output.
Applications Claiming Priority (2)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201710135974.4 | 2017-03-08 | ||
CN201710135974.4A CN106843996A (en) | 2017-03-08 | 2017-03-08 | Conditional compilation preprocess method and device |
Publications (1)
Publication Number | Publication Date |
---|---|
WO2018161509A1 true WO2018161509A1 (en) | 2018-09-13 |
Family
ID=59144012
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
PCT/CN2017/099747 WO2018161509A1 (en) | 2017-03-08 | 2017-08-30 | Conditional compilation preprocessing method, terminal and storage medium |
Country Status (2)
Country | Link |
---|---|
CN (1) | CN106843996A (en) |
WO (1) | WO2018161509A1 (en) |
Families Citing this family (7)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN106843996A (en) * | 2017-03-08 | 2017-06-13 | 百富计算机技术(深圳)有限公司 | Conditional compilation preprocess method and device |
CN107977230A (en) * | 2017-12-01 | 2018-05-01 | 广东雅达电子股份有限公司 | A kind of application management method based on state machine mechanism |
CN109408682B (en) * | 2018-10-30 | 2021-03-23 | 杭州安恒信息技术股份有限公司 | A method, system and device for regular expression matching |
CN110750250A (en) * | 2019-09-06 | 2020-02-04 | 重庆东渝中能实业有限公司 | Method for judging conflict of IO port by using macro compilation |
CN113031963B (en) * | 2021-03-24 | 2023-09-12 | 北京字节跳动网络技术有限公司 | Implementation method, device, equipment and storage medium of conditional compilation |
CN114281319A (en) * | 2021-12-06 | 2022-04-05 | 青岛鼎信通讯股份有限公司 | Shell script-based acquisition terminal program differential compiling method |
CN117555535B (en) * | 2024-01-09 | 2024-05-14 | 云筑信息科技(成都)有限公司 | Method for realizing multi-environment code multiplexing in compact framework |
Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
EP2827244A1 (en) * | 2011-12-15 | 2015-01-21 | Sap Se | Extension mechanism for scripting language compiler |
CN104536797A (en) * | 2015-01-14 | 2015-04-22 | 大唐微电子技术有限公司 | Java program precompiling method and precompiler |
CN104834530A (en) * | 2015-05-27 | 2015-08-12 | 百富计算机技术(深圳)有限公司 | Method for developing POS application program and cloud server |
CN106843996A (en) * | 2017-03-08 | 2017-06-13 | 百富计算机技术(深圳)有限公司 | Conditional compilation preprocess method and device |
Family Cites Families (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
FR2829252B1 (en) * | 2001-08-30 | 2004-10-01 | Gemplus Card Int | COMPRESSION OF AN INTERMEDIATE LANGUAGE PROGRAM |
CN102857493B (en) * | 2012-06-30 | 2015-07-08 | 华为技术有限公司 | Content filtering method and device |
CN104636174B (en) * | 2015-02-02 | 2018-07-10 | 惠州Tcl移动通信有限公司 | Characteristic value definition and application method and system based on android system |
-
2017
- 2017-03-08 CN CN201710135974.4A patent/CN106843996A/en active Pending
- 2017-08-30 WO PCT/CN2017/099747 patent/WO2018161509A1/en active Application Filing
Patent Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
EP2827244A1 (en) * | 2011-12-15 | 2015-01-21 | Sap Se | Extension mechanism for scripting language compiler |
CN104536797A (en) * | 2015-01-14 | 2015-04-22 | 大唐微电子技术有限公司 | Java program precompiling method and precompiler |
CN104834530A (en) * | 2015-05-27 | 2015-08-12 | 百富计算机技术(深圳)有限公司 | Method for developing POS application program and cloud server |
CN106843996A (en) * | 2017-03-08 | 2017-06-13 | 百富计算机技术(深圳)有限公司 | Conditional compilation preprocess method and device |
Also Published As
Publication number | Publication date |
---|---|
CN106843996A (en) | 2017-06-13 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US11714611B2 (en) | Library suggestion engine | |
WO2018161509A1 (en) | Conditional compilation preprocessing method, terminal and storage medium | |
US11740876B2 (en) | Method and system for arbitrary-granularity execution clone detection | |
US10133649B2 (en) | System and methods for model-based analysis of software | |
CN111796831B (en) | Compiling method and device for multi-chip compatibility | |
US8473899B2 (en) | Automatic optimization of string allocations in a computer program | |
US10437574B2 (en) | System and method for providing code completion features for code modules | |
US20140359566A1 (en) | Resolution of textual code in a graphical hierarchical model of a technical computing environment | |
US20140173563A1 (en) | Editor visualizations | |
US9940104B2 (en) | Automatic source code generation | |
US20200210158A1 (en) | Automated or machine-enhanced source code debugging | |
US10360004B2 (en) | Using dynamic information to refine control flow graphs | |
US9311077B2 (en) | Identification of code changes using language syntax and changeset data | |
CN108139891A (en) | Include suggesting for the missing of external file | |
WO2023059390A1 (en) | Copy-paste-update edit automation | |
Sengupta | Julia High Performance: Optimizations, distributed computing, multithreading, and GPU programming with Julia 1.0 and beyond | |
US12182551B2 (en) | Using a semantic tree of a compiler to execute a semantic code query against source code | |
US11119761B2 (en) | Identifying implicit dependencies between code artifacts | |
US20220197617A1 (en) | Idiomatic Source Code Generation | |
Samara | A practical approach for detecting logical error in object oriented environment | |
US20200134476A1 (en) | Generating code performance hints using source code coverage analytics, inspection, and unstructured programming documents | |
WO2024031983A1 (en) | Code management method and related device | |
CN119690807A (en) | Large model assisted static code scanning result analysis method, device, electronic equipment and computer readable storage medium | |
CN117632224A (en) | Code management method and related equipment |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
121 | Ep: the epo has been informed by wipo that ep was designated in this application |
Ref document number: 17899943 Country of ref document: EP Kind code of ref document: A1 |
|
NENP | Non-entry into the national phase |
Ref country code: DE |
|
122 | Ep: pct application non-entry in european phase |
Ref document number: 17899943 Country of ref document: EP Kind code of ref document: A1 |