CN116360788A - Compiling method, compiler and electronic device for structured text programming language - Google Patents
Compiling method, compiler and electronic device for structured text programming language Download PDFInfo
- Publication number
- CN116360788A CN116360788A CN202310167261.1A CN202310167261A CN116360788A CN 116360788 A CN116360788 A CN 116360788A CN 202310167261 A CN202310167261 A CN 202310167261A CN 116360788 A CN116360788 A CN 116360788A
- Authority
- CN
- China
- Prior art keywords
- memory
- preset
- word
- programming language
- syntax tree
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
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
- 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/44—Encoding
- G06F8/447—Target code generation
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/46—Multiprogramming arrangements
- G06F9/50—Allocation of resources, e.g. of the central processing unit [CPU]
- G06F9/5005—Allocation of resources, e.g. of the central processing unit [CPU] to service a request
- G06F9/5011—Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals
- G06F9/5016—Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals the resource being the memory
-
- Y—GENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
- Y02—TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
- Y02D—CLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
- Y02D10/00—Energy efficient computing, e.g. low power processors, power management or thermal management
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- General Engineering & Computer Science (AREA)
- Software Systems (AREA)
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- Stored Programmes (AREA)
Abstract
Description
技术领域technical field
本申请属于语言编译技术领域,尤其涉及一种结构化文本编程语言的编译方法、编译器及电子设备。The application belongs to the technical field of language compiling, and in particular relates to a compiling method of a structured text programming language, a compiler and electronic equipment.
背景技术Background technique
国际电工委员会(International Electrotechnical Commission,IEC)制定的IEC61131-3国际标准定义了5种标准编程语言,分别为梯形图(Ladder,LAD)编程语言、功能块图(Function Block Diagram,FBD)编程语言、顺序功能图(Sequential FunctionChart,SFC)编程语言、指令表(Instruction List,IL)编程语言及结构化文本(StructuredText,ST)编程语言。其中,ST编程语言与C语言类似,具有语法简单和代码结构紧凑等特点,非常适合编写复杂的控制逻辑。The IEC61131-3 international standard formulated by the International Electrotechnical Commission (International Electrotechnical Commission, IEC) defines five standard programming languages, namely the Ladder (Ladder, LAD) programming language, the Function Block Diagram (Function Block Diagram, FBD) programming language, Sequential Function Chart (Sequential FunctionChart, SFC) programming language, instruction list (Instruction List, IL) programming language and structured text (StructuredText, ST) programming language. Among them, the ST programming language is similar to the C language, has the characteristics of simple syntax and compact code structure, and is very suitable for writing complex control logic.
目前,常用的ST编程语言的编译方法是将ST编程语言转换成C语言,然后再通过GNU编译器套件(GNU Compiler Collection,GCC)将该C语言编译成机器码,这种方法由于增加了将ST编程语言转换成C语言的转换时间,因此导致ST编程语言的编译效率较低。At present, the commonly used compilation method of the ST programming language is to convert the ST programming language into C language, and then compile the C language into machine code through the GNU Compiler Collection (GCC). The conversion time of the ST programming language into the C language, thus resulting in low compilation efficiency of the ST programming language.
发明内容Contents of the invention
有鉴于此,本申请实施例提供了一种结构化文本编程语言的编译方法、编译器及电子设备,以解决现有的致ST编程语言的编译效率较低的技术问题。In view of this, the embodiments of the present application provide a method for compiling a structured text programming language, a compiler and an electronic device, so as to solve the existing technical problem of low compiling efficiency of the ST programming language.
第一方面,本申请实施例提供一种结构化文本编程语言的编译方法,包括:In the first aspect, the embodiment of the present application provides a method for compiling a structured text programming language, including:
基于预设词法规则将待编译的源程序分割为一个或多个分词;Divide the source program to be compiled into one or more word segmentations based on preset lexical rules;
基于预设语法规则对各个所述分词进行语法分析,并基于分析出的语法正确的所述分词确定语法正确的目标语法树;performing grammatical analysis on each of the word segmentations based on preset grammatical rules, and determining a grammatically correct target syntax tree based on the analyzed grammatically correct word segmentation;
基于所述目标语法树生成所述源程序对应的目标代码;generating an object code corresponding to the source program based on the object syntax tree;
基于预设内存分配算法确定所述各个所述分词的第一内存地址,并对各个所述第一内存地址进行内存优化;determining the first memory address of each of the word segments based on a preset memory allocation algorithm, and performing memory optimization on each of the first memory addresses;
基于内存优化后的所有所述第一内存地址对所述目标代码进行编译,得到所述源程序的编译结果。Compile the target code based on all the first memory addresses after memory optimization to obtain a compilation result of the source program.
可选的,所述分词的分词类型包括注释符号、标识符号、关键字、变量、数值文字、四则运算符号、数组符号和/或结束符号;Optionally, the word segmentation type of the word segmentation includes comment symbols, identifier symbols, keywords, variables, numerical literals, arithmetic symbols, array symbols and/or end symbols;
对应地,所述基于预设词法规则将待编译的源程序分割为一个或多个分词,包括:Correspondingly, dividing the source program to be compiled into one or more word segmentations based on preset lexical rules includes:
基于预设识别函数对所述源程序进行词法分析;所述预设识别函数是基于预设词法规则构建的;performing lexical analysis on the source program based on a preset recognition function; the preset recognition function is constructed based on preset lexical rules;
基于所述词法分析的结果,将所述源程序分割为一个或多个分词类型包括注释符号、标识符号、关键字、变量、数值文字、四则运算符号、数组符号和/或结束符号的分词。Based on the result of the lexical analysis, the source program is divided into one or more word segmentation types including comment symbols, identifier symbols, keywords, variables, numerical literals, arithmetic symbols, array symbols and/or end symbols.
可选的,所述基于分析出的语法正确的所述分词生成正确的目标语法树,包括:Optionally, the generating a correct target syntax tree based on the analyzed grammatically correct word segmentation includes:
基于语法正确的所述分词生成第一语法树;generating a first syntax tree based on the grammatically correct word segmentation;
对所述第一语法树进行语义分析,并基于所述语义分析的结果确定所述目标语法树。Perform semantic analysis on the first syntax tree, and determine the target syntax tree based on a result of the semantic analysis.
可选的,所述对所述第一语法树进行语义分析,并基于所述语义分析结果确定所述目标语法树,包括:Optionally, performing semantic analysis on the first syntax tree, and determining the target syntax tree based on the semantic analysis result includes:
基于预设语义分析函数对所述第一语法树进行类型检查,确定所述第一语法树中语义错误的分词和语义正确的分词;performing a type check on the first syntax tree based on a preset semantic analysis function, and determining semantically incorrect word segmentation and semantically correct word segmentation in the first syntax tree;
基于所述第一语法树中所有语义正确的所述分词,对所述第一语法树中的各个分词对应的数据类型进行更新;Based on all the semantically correct participles in the first grammatical tree, update the data type corresponding to each participle in the first grammatical tree;
基于所述第一语法树中所有语义正确的所述分词和更新后的各个所述分词对应的数据类型,确定所述目标语法树Determine the target syntax tree based on all the semantically correct word segmentations in the first syntax tree and the updated data types corresponding to each of the word segmentations
可选的,还包括:Optionally, also include:
对所述第一语法树中语义错误的所述分词进行语义修正,将语义错误的所述分词修正为语义正确的分词。Semantic correction is performed on the word segmentation with semantic error in the first syntax tree, and the word segmentation with semantic error is corrected into a word segmentation with correct semantics.
可选的,所述预设内存分配算法包括静态内存分配算法和动态内存分配算法;所述基于预设内存分配算法确定所述各个所述分词的第一内存地址,包括:Optionally, the preset memory allocation algorithm includes a static memory allocation algorithm and a dynamic memory allocation algorithm; determining the first memory address of each word segment based on the preset memory allocation algorithm includes:
确定各个所述分词的第一数据类型;所述第一数据类型包括直接指定地址类型和非直接指定地址类型;Determining the first data type of each of the word segmentations; the first data type includes a directly specified address type and an indirect specified address type;
将各个所述第一数据类型为所述直接指定地址类型的第一分词的预设内存地址分别确定为各个所述第一分词的第一内存地址;所述预设内存地址为预先基于所述静态内存分配算法为各个所述分词分配的内存地址;Each of the first data type is the preset memory address of the first participle of the directly specified address type respectively determined as the first memory address of each of the first participle; the preset memory address is pre-based on the The memory address allocated by the static memory allocation algorithm for each of the word segmentations;
基于所述动态内存分配算法,确定各个所述第一数据类型为所述非直接指定地址类型的第二分词的第一内存地址。Based on the dynamic memory allocation algorithm, each of the first data types is determined as a first memory address of a second word segment of the non-directly specified address type.
可选的,所述基于所述动态内存分配算法,确定各个所述第一数据类型为所述非直接指定地址类型的第二分词的第一内存地址,包括:Optionally, based on the dynamic memory allocation algorithm, determining that each of the first data types is the first memory address of the second participle of the non-directly specified address type includes:
确定各个所述第二分词的第二数据类型;所述第二数据类型包括直接表示变量类型和非直接表示变量类型;Determining the second data type of each of the second participle; the second data type includes a direct representation variable type and an indirect representation variable type;
基于各个所述第二数据类型为所述直接表示变量类型的第二分词的内存地址标记符分别确定对应的所述第二分词的第一内存地址;每个所述内存地址标记符分别对应所述第一内存地址中的一个不同的区域;Based on each of the second data types, determine the corresponding first memory address of the second participle for the memory address marker of the second participle that directly represents the variable type; each of the memory address markers corresponds to the corresponding a different area in the first memory address;
基于各个所述第二数据类型为非直接表示变量类型的第二分词的分词类型分别确定对应的所述第二分词的第一内存地址;每个所述分词类型对应所述第一内存地址中的一个不同的区域。Determine the corresponding first memory address of the second participle based on the participle type of the second participle that each of the second data type is a second participle that does not directly represent the variable type; each participle type corresponds to the first memory address of a different region.
第二方面,本申请实施例提供一种结构化文本编程语言的编译器,包括:In the second aspect, the embodiment of the present application provides a compiler for a structured text programming language, including:
第一分割单元,用于基于预设词法规则将待编译的源程序分割为一个或多个分词;a first segmentation unit, configured to segment the source program to be compiled into one or more word segments based on preset lexical rules;
第一确定单元,用于基于预设语法规则对各个所述分词进行语法分析,并基于分析出的语法正确的所述分词确定语法正确的目标语法树;The first determining unit is configured to perform grammatical analysis on each of the word segmentations based on preset grammatical rules, and determine a grammatically correct target syntax tree based on the analyzed grammatically correct word segmentation;
第一生成单元,用于基于所述目标语法树生成所述源程序对应的目标代码;a first generating unit, configured to generate an object code corresponding to the source program based on the object syntax tree;
第二确定单元,用于基于预设内存分配算法确定所述各个所述分词的第一内存地址,并对各个所述第一内存地址进行内存优化;The second determination unit is configured to determine the first memory address of each of the word segmentations based on a preset memory allocation algorithm, and perform memory optimization on each of the first memory addresses;
第一编译单元,用于基于内存优化后的所有所述第一内存地址对所述目标代码进行编译,得到所述源程序的编译结果。The first compiling unit is configured to compile the target code based on all the first memory addresses after memory optimization, and obtain a compiling result of the source program.
第三方面,本申请实施例提供一种电子设备,包括存储器、处理器以及存储在所述存储器中并可在所述处理器上运行的计算机程序,所述处理器执行所述计算机程序时实现如上述第一方面任一项所述编译方法中的各步骤。In a third aspect, an embodiment of the present application provides an electronic device, including a memory, a processor, and a computer program stored in the memory and operable on the processor, and the computer program is implemented when the processor executes the computer program. The steps in the compilation method are as described in any one of the above first aspects.
第四方面,本申请实施例提供一种计算机可读存储介质所述计算机可读存储介质存储有计算机程序,所述计算机程序被处理器执行时实现如上述第一方面任一项所述的编译方法中的各步骤。In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium. The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the compilation described in any one of the above-mentioned first aspects is implemented. steps in the method.
第五方面,本申请实施例提供一种计算机程序产品,当计算机程序产品在终端设备上运行时,使得终端设备执行如上述第一方面或第一方面的任一可选方式所述的方法中的各步骤。In the fifth aspect, the embodiment of the present application provides a computer program product, which, when the computer program product is run on the terminal device, enables the terminal device to execute the method described in the first aspect or any optional mode of the first aspect each step.
本申请实施例提供的结构化文本编程语言的编译方法、编译器及电子设备具有以下有益效果:The compilation method, compiler and electronic equipment of the structured text programming language provided by the embodiment of the present application have the following beneficial effects:
本申请实施例提供的结构化文本编程语言的编译方法,通过基于预设词法规则将待编译的源程序分割为一个或多个分词,基于预设语法规则对各个分词进行语法分析,并基于分析出的语法正确的分词确定语法正确的目标语法树;基于目标语法树生成源程序对应的目标代码;基于预设内存分配算法确定各个分词的第一内存地址,并对各个第一内存地址进行内存优化;基于内存优化后的所有第一内存地址对所述目标代码进行编译,从而得到源程序的编译结果。如此,采用本申请实施例提供的结构化文本编程语言的编译方法能够实现对结构化文本编程语言的直接编译,而无需将结构化文本编程语言转成C语言之后再对其进行编译,从而能够节省出将结构化文本编程语言转成C语言的转换时间,提高结构化文本编程语言的编译效率。The method for compiling a structured text programming language provided by the embodiment of the present application divides the source program to be compiled into one or more word segments based on preset lexical rules, performs grammatical analysis on each segment based on preset grammatical rules, and based on the analysis The grammatically correct word segmentation determines the grammatically correct target syntax tree; generates the target code corresponding to the source program based on the target syntax tree; determines the first memory address of each word segmentation based on the preset memory allocation algorithm, and performs memory for each first memory address Optimizing: compiling the target code based on all the first memory addresses after memory optimization, so as to obtain a compilation result of the source program. In this way, the method for compiling the structured text programming language provided by the embodiment of the present application can realize the direct compilation of the structured text programming language, without converting the structured text programming language into C language and then compiling it, thereby enabling The conversion time for converting the structured text programming language into the C language is saved, and the compilation efficiency of the structured text programming language is improved.
附图说明Description of drawings
为了更清楚地说明本申请实施例中的技术方案,下面将对实施例或现有技术描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本申请的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动性的前提下,还可以根据这些附图获得其他的附图。In order to more clearly illustrate the technical solutions in the embodiments of the present application, the accompanying drawings that need to be used in the descriptions of the embodiments or the prior art will be briefly introduced below. Obviously, the accompanying drawings in the following description are only for the present application For some embodiments, those of ordinary skill in the art can also obtain other drawings based on these drawings without paying creative efforts.
图1为本申请实施例提供的一种ST编程语言的编译方法的实现流程图;Fig. 1 is the implementation flowchart of a kind of compiling method of ST programming language that the embodiment of the application provides;
图2为本申请实施例提供的一种将待编译的源程序分割为一个或多个分词的实现流程图;Fig. 2 is a kind of implementation flowchart that divides the source program to be compiled into one or more word segmentations provided by the embodiment of the present application;
图3为本申请实施例提供的一种基于分析出的语法正确的分词确定语法正确的目标语法树的实现流程图;FIG. 3 is an implementation flowchart of determining a grammatically correct target grammar tree based on the analyzed grammatically correct word segmentation provided by the embodiment of the present application;
图4为本申请实施例提供的一种生成的第一语法树的示意图;FIG. 4 is a schematic diagram of a generated first syntax tree provided by an embodiment of the present application;
图5为本申请实施例提供的一种基于预设内存分配算法确定各个分词的第一内存地址的实现流程图;FIG. 5 is an implementation flow chart of determining the first memory address of each word segment based on a preset memory allocation algorithm provided by an embodiment of the present application;
图6为本申请实施例提供的一种结构化文本编程语言的编译器的结构示意图;FIG. 6 is a schematic structural diagram of a compiler for a structured text programming language provided by an embodiment of the present application;
图7为本申请实施例提供的一种电子设备的结构示意图。FIG. 7 is a schematic structural diagram of an electronic device provided by an embodiment of the present application.
具体实施方式Detailed ways
需要说明的是,本申请实施例使用的术语仅用于对本申请的具体实施例进行解释,而非旨在限定本申请。在本申请实施例的描述中,除非另有说明,“多个”是指两个或多于两个,“至少一个”、“一个或多个”是指一个、两个或两个以上。术语“第一”、“第二”仅用于描述目的,而不能理解为指示或暗示相对重要性或者隐含指明所指示的技术特征的数量。由此,限定有“第一”、“第二”特征可以明示或者隐含地包括一个或者更多个该特征。It should be noted that the terms used in the embodiments of the present application are only used to explain the specific embodiments of the present application, and are not intended to limit the present application. In the description of the embodiments of the present application, unless otherwise specified, "plurality" refers to two or more than two, and "at least one" and "one or more" refers to one, two or more than two. The terms "first" and "second" are used for descriptive purposes only, and cannot be interpreted as indicating or implying relative importance or implicitly specifying the quantity of indicated technical features. Thus, the definition of "first" and "second" features may expressly or implicitly include one or more of these features.
在本说明书中描述的参考“一个实施例”或“一些实施例”等意味着在本申请的一个或多个实施例中包括结合该实施例描述的特定特征、结构或特点。由此,在本说明书中的不同之处出现的语句“在一个实施例中”、“在一些实施例中”、“在其他一些实施例中”、“在另外一些实施例中”等不是必然都参考相同的实施例,而是意味着“一个或多个但不是所有的实施例”,除非是以其他方式另外特别强调。术语“包括”、“包含”、“具有”及它们的变形都意味着“包括但不限于”,除非是以其他方式另外特别强调。Reference to "one embodiment" or "some embodiments" or the like in this specification means that a particular feature, structure, or characteristic described in connection with the embodiment is included in one or more embodiments of the present application. Thus, appearances of the phrases "in one embodiment," "in some embodiments," "in other embodiments," "in other embodiments," etc. in various places in this specification are not necessarily All refer to the same embodiment, but mean "one or more but not all embodiments" unless specifically stated otherwise. The terms "including", "comprising", "having" and variations thereof mean "including but not limited to", unless specifically stated otherwise.
本申请实施例提供的ST编程语言的编译方法的执行主体可以为电子设备。示例性的,电子设备可以包括手机、平板电脑、笔记本电脑及台式电脑等。The executing subject of the ST programming language compiling method provided in the embodiment of the present application may be an electronic device. Exemplarily, the electronic equipment may include a mobile phone, a tablet computer, a notebook computer, a desktop computer, and the like.
电子设备中可以安装有ST编程语言的编译器。当用户想要对一段ST编程语言的源程序进行编译时,可以打开电子设备中的编译器,并将待编译的ST编程语言的源程序输入至ST编程语言的编译器中,且触发编译器中的编译按钮。电子设备检测到编译器中的编译按钮被触发时,通过执行本申请实施例提供的ST编程语言的编译方法的各个步骤,能够实现对ST编程语言的直接编译,从而无需将ST编程语言转换为C语言再进行编译,提高了ST编程语言的编译效率。A compiler for the ST programming language may be installed in the electronic device. When the user wants to compile a source program of ST programming language, he can open the compiler in the electronic device, and input the source program of ST programming language to be compiled into the compiler of ST programming language, and trigger the compiler Compile button in . When the electronic device detects that the compiling button in the compiler is triggered, by executing each step of the compiling method of the ST programming language provided by the embodiment of the present application, the direct compiling of the ST programming language can be realized, so that there is no need to convert the ST programming language into The C language is then compiled to improve the compilation efficiency of the ST programming language.
请参阅图1,图1为本申请实施例提供的一种ST编程语言的编译方法的实现流程图,该ST编程语言的编译方法可以包括S101~S105,详述如下:Please refer to Fig. 1, Fig. 1 is the realization flow chart of a kind of ST programming language compiling method provided by the embodiment of the present application, the compiling method of this ST programming language may include S101~S105, detailed description is as follows:
在S101中,基于预设词法规则将待编译的源程序分割为一个或多个分词。In S101, the source program to be compiled is divided into one or more word segments based on preset lexical rules.
在具体应用,当需要对ST编程语言进行编译时,电子设备可以获取待编译的ST编程语言的源程序。In a specific application, when the ST programming language needs to be compiled, the electronic device can obtain the source program of the ST programming language to be compiled.
可选的,电子设备获取待编译的ST编程语言的源程序的方式例如可以为:基于字符串方式从编译器读取待编译的ST编程语言的源程序。Optionally, the manner in which the electronic device acquires the source program of the ST programming language to be compiled may be, for example, reading the source program of the ST programming language to be compiled from a compiler based on a character string.
电子设备获取到待编译的ST编程语言的源程序后,可以并基于预设词法规则将该将待编译的源程序分割为一个或多个分词。After the electronic device obtains the source program of the ST programming language to be compiled, it can divide the source program to be compiled into one or more word segments based on preset lexical rules.
预设词法规则可以用于描述将ST编程语言的源代码分割为分词的分割策略。示例性的,分词的分词类型可以包括注释符号、标识符号、关键字、变量、数值文字、四则运算符号、数组符号和/或结束符号等。The preset lexical rules can be used to describe a segmentation strategy for segmenting the source code of the ST programming language into word segments. Exemplarily, the word segmentation type of the word segmentation may include comment symbols, identifier symbols, keywords, variables, numerical literals, four arithmetic operation symbols, array symbols and/or end symbols, and the like.
在一种可能的实现方式中,S101可以通过如图2所示的S1011~S1012实现,详述如下:In a possible implementation manner, S101 can be implemented through S1011-S1012 as shown in Figure 2, and the details are as follows:
在S1011中,基于预设识别函数对所述源程序进行词法分析。In S1011, perform lexical analysis on the source program based on a preset identification function.
其中,预设识别函数是基于预设词法规则构建的,用于描述ST编程语言源程序中的字符与分词之间的关系。Among them, the preset recognition function is constructed based on preset lexical rules, and is used to describe the relationship between characters and word segmentation in the ST programming language source program.
在本实现方式中,电子设备基于预设识别函数对ST编程语言的源程序进行词法分析时,可以依次判断待编译的ST编程语言的源程序中的每一个字符是否为空字符。当某个字符为非空字符时,可以基于预设识别函数对该非空字符进行词法分析,得到该非空字符的词法分析结果。非空字符的词法分析结果可以用于描述非空字符的分词类型。In this implementation, when the electronic device performs lexical analysis on the ST programming language source program based on the preset recognition function, it may sequentially determine whether each character in the ST programming language source program to be compiled is a null character. When a certain character is a non-null character, lexical analysis may be performed on the non-null character based on a preset recognition function to obtain a lexical analysis result of the non-null character. The lexical analysis results of non-null characters can be used to describe the word segmentation type of non-null characters.
在S1012中,基于所述词法分析的结果,将所述源程序分割为一个或多个分词类型包括注释符号、标识符号、关键字、变量、数值文字、四则运算符号、数组符号和/或结束符号的分词。In S1012, based on the result of the lexical analysis, the source program is divided into one or more word segmentation types including comment symbols, identifier symbols, keywords, variables, numerical literals, four arithmetic symbols, array symbols and/or end participle of symbols.
在本实现方式中,可以基于待编译的ST编程语言的源程序中每一个非空字符的词法分析结果,获取该源程序对应的所有分词。示例性的,若待编译的ST编程语言的源程序中第一个非空字符对应的分词为注释符号,则将该源程序的第一个分词确定为注释符号;若该源程序中第一个非空字符对应的分词为标识符号,则将该源程序的第一个分词则确定为标识符号,以此类推,直至获取该源程序的所有分词为止。In this implementation, based on the lexical analysis result of each non-null character in the source program of the ST programming language to be compiled, all word segmentations corresponding to the source program can be obtained. Exemplarily, if the participle corresponding to the first non-null character in the source program of the ST programming language to be compiled is a comment symbol, then the first participle of the source program is determined to be a comment symbol; if the first participle in the source program If the word segmentation corresponding to non-null characters is an identifier symbol, then the first word segmentation of the source program is determined as an identifier symbol, and so on until all the word segmentation of the source program is obtained.
在S102中,基于预设语法规则对各个分词进行语法分析,并基于分析出的语法正确的分词确定语法正确的目标语法树。In S102, perform grammatical analysis on each participle based on preset grammatical rules, and determine a grammatically correct target syntax tree based on the analyzed grammatically correct participle.
可选的,当电子设备将待编译的源程序分割为一个或多个分词后,电子设备可以基于预设语法规则将各个分词组合成短语,并对组合得到的短语进行语法检查,得到语法正确的分词和语法错误的分词,并将语法错误的分词修改为语法正确的分词以保证全部分词均为语法正确的分词。Optionally, after the electronic device divides the source program to be compiled into one or more word segments, the electronic device can combine each word segment into a phrase based on preset grammar rules, and perform a grammar check on the combined phrase to obtain a correct grammar Word segmentation and grammatically incorrect word segmentation, and modify the grammatically incorrect word segmentation to grammatically correct word segmentation to ensure that all the word segmentation is grammatically correct.
预设语法规则可以用于描述正确语法的表达逻辑。Preset grammar rules can be used to describe the expression logic of correct grammar.
在一种可能的实现方式中,S102中基于分析出的语法正确的分词确定语法正确的目标语法树的步骤可以通过如图3所示的S1021~S1022实现,详述如下:In a possible implementation, the step of determining a grammatically correct target syntax tree based on the analyzed grammatically correct word segmentation in S102 can be implemented through S1021-S1022 as shown in FIG. 3 , and the details are as follows:
在S1021中,基于语法正确的分词生成第一语法树。In S1021, a first syntax tree is generated based on grammatically correct word segmentation.
可选的,在电子设备基于语法分析的结果分析出语法正确的分词以后,电子设备可以基于该语法正确的分词生成第一语法树。Optionally, after the electronic device analyzes the grammatically correct word segmentation based on the result of the syntax analysis, the electronic device may generate the first syntax tree based on the grammatically correct word segmentation.
示例性的,假设语法正确的分词如下:Exemplarily, it is assumed that the grammatically correct word segmentation is as follows:
CC:=AA+BB;CC:=AA+BB;
RET:=FUN_0(D1);RET:=FUN_0(D1);
则电子设备基于以上语法正确的分词生成的第一语法树可以如图4所示。Then, the first syntax tree generated by the electronic device based on the above grammatically correct word segmentation may be as shown in FIG. 4 .
在S1022中,对第一语法树进行语义分析,并基于语义分析的结果确定目标语法树。In S1022, semantic analysis is performed on the first syntax tree, and a target syntax tree is determined based on the result of the semantic analysis.
可选的,电子设备在基于语法正确的分词生成第一语法树后,可以对该第一语法树进行语义分析,以确定出第一目标语法树中语义正确的分词和语音错误的分词,并基于第一语法树中所有语义正确的分词生成目标语法树。即,目标语法树由所有语法正确且语义正确的分词组成。Optionally, after the electronic device generates the first syntax tree based on the grammatically correct word segmentation, it may perform semantic analysis on the first syntax tree to determine the semantically correct word segmentation and phonetically incorrect word segmentation in the first target syntax tree, and A target syntax tree is generated based on all semantically correct word segmentations in the first syntax tree. That is, the target syntax tree consists of all syntactically correct and semantically correct tokens.
其中,语义正确的分词指符合预设语言规范的分词。预设语言规范可以基于实际应用设定。Among them, the semantically correct word segmentation refers to the word segmentation that conforms to the preset language specification. The default language specification can be set based on actual applications.
在一种可能的实现方式中,S1022可以包括以下步骤:In a possible implementation manner, S1022 may include the following steps:
步骤a:基于预设语义分析函数对第一语法树进行类型检查,确定第一语法树中语义错误的分词和语义正确的分词。Step a: Perform a type check on the first syntax tree based on a preset semantic analysis function, and determine semantically incorrect word segmentation and semantically correct word segmentation in the first syntax tree.
可选的,所述预设语义分析函数可以用于判断第一语法树中每个分词是否具有预设语言规范允许的运算对象,若分词具有预设语言规范允许的运算对象,则确定该分词为语义正确的分词,若分词不具有预设语言规范允许的运算对象,则确定该分词为语义错误的分词。在实际应用中,电子设备可以遍历第一语法树中的各个分词,以确定该第一语法树中所有的语义正确的分词和语义错误的分词。Optionally, the preset semantic analysis function may be used to determine whether each word segment in the first syntax tree has an operand allowed by the preset language specification, and if the word segment has an operand allowed by the preset language specification, then determine the word segment is a semantically correct word segment, and if the word segment does not have an operand allowed by the preset language specification, it is determined that the word segment is a semantically incorrect word segment. In practical applications, the electronic device may traverse each word segment in the first syntax tree to determine all semantically correct word segments and semantically incorrect word segments in the first syntax tree.
在本申请实施例中,电子设备在确定该第一语法树中所有的语义正确的分词和语义错误的分词后,还可以对语义错误的分词进行出错管理。出错管理的具体方式例如可以为:对第一语法树中语义错误的分词进行语义修正,以将语义错误的分词修正为语义正确的分词。In the embodiment of the present application, after determining all semantically correct word segments and semantically incorrect word segments in the first syntax tree, the electronic device may further perform error management on semantically incorrect word segments. A specific manner of error management may be, for example: perform semantic correction on the word segmentation with semantic error in the first syntax tree, so as to correct the word segmentation with semantic error into a word segmentation with correct semantics.
步骤b:基于第一语法树中的所有语义正确的分词,对第一语法树中的各个分词对应的数据类型进行更新。Step b: Based on all the semantically correct word segments in the first syntax tree, update the data type corresponding to each word segment in the first syntax tree.
可选的,电子设备在将第一语法树中的错误语义的分词修正为正确语义的分词后,需要同步地对符号表信息进行更新。具体地,可以将错误语义的分词的符号表信息进行删除,并增加进行修正后的正确语义的分词的符号表信息。Optionally, the electronic device needs to update the symbol table information synchronously after correcting the word segmentation with incorrect semantics in the first syntax tree to the word segmentation with correct semantics. Specifically, the symbol table information of word segmentations with wrong semantics may be deleted, and the corrected symbol table information of word segmentations with correct semantics may be added.
步骤c:基于第一语法树中的所有语义正确的分词和更新后的的各个分词对应的数据类型,确定目标语法树。Step c: Determine the target syntax tree based on all the semantically correct word segments in the first syntax tree and the updated data types corresponding to each word segment.
可选的,电子设备在将第一语法树中的错误语义的分词修正为正确语义的分词并更新了各个分词对应的数据类型后,可以基于所有正确语义的分词和更新后的符号表信息,确定目标语法树。Optionally, after the electronic device corrects the word segmentations with incorrect semantics in the first syntax tree to word segmentations with correct semantics and updates the data types corresponding to each word segmentation, based on all the word segmentations with correct semantics and the updated symbol table information, Determine the target syntax tree.
在S103中,基于目标语法树生成源程序对应的目标代码。In S103, an object code corresponding to the source program is generated based on the object syntax tree.
可选的,电子设备在得到目标语法树后,可以遍历整个目标语法树将该目标语法树转换成编译器可以识别并编译的目标代码,在实际应用中,目标代码可以为预设指令列表(Unimat Instruct List,UIL)格式的代码。其中,UIL是一种符号单一的低级别指令列表格式。Optionally, after the electronic device obtains the target syntax tree, it can traverse the entire target syntax tree and convert the target syntax tree into target code that can be recognized and compiled by the compiler. In practical applications, the target code can be a list of preset instructions ( Unimat Instruct List, UIL) format codes. Among them, UIL is a low-level instruction list format with a single symbol.
示例性的,电子设备基于目标语法树生成的源程序对应的目标代码可以为:Exemplarily, the target code corresponding to the source program generated by the electronic device based on the target syntax tree may be:
在S104中,基于预设内存分配算法确定各个分词的第一内存地址,并对各个第一内存地址进行内存优化。In S104, the first memory address of each word segment is determined based on a preset memory allocation algorithm, and memory optimization is performed on each first memory address.
在本申请实施例中,预设内存分配算法可以包括静态内存分配算法和动态内存分配算法。In this embodiment of the present application, the preset memory allocation algorithm may include a static memory allocation algorithm and a dynamic memory allocation algorithm.
可选的,S104中基于预设内存分配算法确定各个分词的第一内存地址的步骤可以通过如图5所示的S1041~S1042实现,详述如下:Optionally, the step of determining the first memory address of each word segment based on the preset memory allocation algorithm in S104 can be realized through S1041-S1042 as shown in Figure 5, and the details are as follows:
在S1041中,确定各个分词的第一数据类型;In S1041, determine the first data type of each participle;
其中,第一数据类型包括直接指定地址类型和非直接指定地址类型。Wherein, the first data type includes directly specified address type and non-directly specified address type.
示例性的,分词类型为注释符号、标识符号、关键字、数值文字、四则运算符号、数组符号、结束符号以及直接表示型变量等分词的第一数据类型可以为直接指定地址类型,分词类型为变量(例如用户数据)的分词的第一数据类型可以为非直接指定地址类型。Exemplarily, the word segmentation types are comment symbols, identification symbols, keywords, numeric characters, four arithmetic operation symbols, array symbols, end symbols, and direct expression variables. The first data type of the word segmentation can be a directly specified address type, and the word segmentation type is The first data type of the word segmentation of variables (such as user data) may be an indirect specified address type.
在S1042中,将各个第一数据类型为直接指定地址类型的第一分词的预设内存地址分别确定为各个第一分词的第一内存地址。In S1042, the preset memory address of each first participle whose first data type is a directly specified address type is respectively determined as the first memory address of each first participle.
其中,预设内存地址为预先基于静态内存分配算法为各个分词分配的内存地址。静态内存分配算法用于描述预先为分词分配内存地址的具体方法,此处不作特殊限定。Wherein, the preset memory address is a memory address pre-allocated for each word segmentation based on a static memory allocation algorithm. The static memory allocation algorithm is used to describe the specific method of pre-allocating memory addresses for word segmentation, and there is no special limitation here.
在实际应用中,可以预先为各个内存区域划定固定的范围,并为各个区域设置相应的内存地址标识符,其中,每个内存地址标记符分别对应第一内存地址中的一个不同的内存区域,可以先根据内存地址标记符确定第一内存地址对应的内存区域,再基于偏移量确定第一内存地址。在实际应用中,可以先基于表1的第一列和第二列来确定内存地址标记符对应的第一内存地址对应的内存区域。In practical applications, fixed ranges can be defined for each memory area in advance, and corresponding memory address identifiers can be set for each area, wherein each memory address identifier corresponds to a different memory area in the first memory address respectively , the memory area corresponding to the first memory address may be determined first according to the memory address marker, and then the first memory address may be determined based on the offset. In practical applications, the memory area corresponding to the first memory address corresponding to the memory address marker can be determined based on the first column and the second column of Table 1.
表1Table 1
其中,M区为辅助继电器,S区为状态寄存器,D区为数据寄存器,R区为文件寄存器。Among them, the M area is the auxiliary relay, the S area is the status register, the D area is the data register, and the R area is the file register.
示例性的,当分词的内存地址标识符为X时,可以确定第一内存地址对应的区域为输出区位元件,当分词的内存地址标识符为M或B时,可以确定第一内存地址对应的内存区域为辅助继电器,以此类推。Exemplarily, when the memory address identifier of the word segmentation is X, it can be determined that the area corresponding to the first memory address is the output location element; when the memory address identifier of the word segmentation is M or B, it can be determined that the area corresponding to the first memory address The memory area is the auxiliary relay, and so on.
在确定了第一内存地址对应的内存区域后,可以基于偏移量确定第一内存地址。示例性的,如表1中的第三列中的“%X5”则表示内存地址标识符为X,偏移量为5,则可以将输出区位元件的第五位确定为第一内存地址;如表1中的第三列中的“%M3”则表示内存地址标识符为M,偏移量为3,则可以将辅助继电器的第三位确定为第一内存地址,以此类推。After the memory area corresponding to the first memory address is determined, the first memory address may be determined based on the offset. Exemplarily, if "%X5" in the third column in Table 1 indicates that the memory address identifier is X and the offset is 5, the fifth bit of the output area element can be determined as the first memory address; For example, "%M3" in the third column in Table 1 indicates that the memory address identifier is M and the offset is 3, then the third bit of the auxiliary relay can be determined as the first memory address, and so on.
在S1043中,基于动态内存分配算法,确定各个第一数据类型为非直接指定地址类型的第二分词的第一内存地址。In S1043, based on the dynamic memory allocation algorithm, determine the first memory address of the second participle whose first data type is the non-directly specified address type.
可选的,S1043可以包括以下步骤:Optionally, S1043 may include the following steps:
步骤d:确定各个第二分词的所需内存容量值与预设内存阈值之间的关系。Step d: Determine the relationship between the required memory capacity value of each second participle and the preset memory threshold.
其中,预设内存阈值可以基于实际需求确定,此处不作限定。Wherein, the preset memory threshold may be determined based on actual requirements, which is not limited here.
步骤e:若第二分词的所需内存容量值小于预设内存阈值,则基于预设固定分配规则确定第二分词的第一内存地址。Step e: If the required memory capacity value of the second participle is smaller than the preset memory threshold, then determine the first memory address of the second participle based on a preset fixed allocation rule.
示例性的,预设固定分配规则可以为:查找空闲分区的时候增加一个指针指示下一次开始查询的空闲区地址,每次查找结束后,计算从起始位置到这个指针之间的容量,当下一次需要查找空闲分区时,如果所需内存容量值小于所记录的最大容量,就可以从开始位置开始查找来确定第二分词的第一内存地址,若所需容量大于所记录的最大容量,则从该指针的位置开始查找来确定第二分词的第一内存地址。Exemplarily, the preset fixed allocation rule can be: when searching for a free partition, add a pointer to indicate the address of the free area to start querying next time, after each search, calculate the capacity between the starting position and the pointer, and now When you need to find a free partition, if the required memory capacity value is less than the recorded maximum capacity, you can start searching from the start position to determine the first memory address of the second participle, if the required capacity is greater than the recorded maximum capacity, then Start searching from the position of the pointer to determine the first memory address of the second participle.
步骤f:若第二分词的所需内存容量值大于预设内存阈值,则基于第二分词的所需内存值确定第二分词的第一内存地址。Step f: If the required memory capacity value of the second participle is greater than the preset memory threshold, then determine the first memory address of the second participle based on the required memory value of the second participle.
在本申请实施例中,当第二分词的所需内存值大于预设内存阈值时,可以根据第二分词的实际所需内存确定第二分词的第一内存地址。In the embodiment of the present application, when the required memory value of the second participle is greater than the preset memory threshold, the first memory address of the second participle may be determined according to the actual required memory of the second participle.
可选的,电子设备在确定了各个分词的第一内存地址后,可以对各个第一内存地址进行内存优化。具体的,电子设备可以遍历各个分词对应的第一内存地址,确定第一内存地址中的冗余内存,并对冗余内存进行删除。电子设备还可以遍历各个分词,确定冗余变量和逻辑复杂的分词,对冗余变量进行删除。对逻辑复杂的分词进行精简。此外,电子设备还可以对各个分词中能够进行预先运算的分词进行运算,并对各个分词对应的指令进行优化以提高整体的编译效率。Optionally, after the electronic device determines the first memory address of each word segment, memory optimization may be performed on each first memory address. Specifically, the electronic device may traverse the first memory address corresponding to each word segment, determine the redundant memory in the first memory address, and delete the redundant memory. The electronic device can also traverse each participle, determine redundant variables and participles with complex logic, and delete redundant variables. Simplify logically complex word segmentation. In addition, the electronic device can also perform calculations on the word segments that can be pre-calculated in each word segment, and optimize the instructions corresponding to each word segment to improve the overall compilation efficiency.
在S105中,基于内存优化后的所有第一内存地址对目标代码进行编译,得到源程序的编译结果。In S105 , the target code is compiled based on all the memory-optimized first memory addresses to obtain a compilation result of the source program.
可选的,电子设备在得到目标代码和内存优化后的第一内存地址后,可以基于所有内存优化后的第一内存地址对目标代码进行编译,以得到待编译的ST语言的源程序的编译结果。Optionally, after the electronic device obtains the target code and the memory-optimized first memory address, it can compile the target code based on all the memory-optimized first memory addresses, so as to obtain the compilation of the ST language source program to be compiled result.
从以上可以看出,本申请实施例提供的结构化文本编程语言的编译方法,通过基于预设词法规则将待编译的源程序分割为一个或多个分词,基于预设语法规则对各个分词进行语法分析,并基于分析出的语法正确的分词确定语法正确的目标语法树;基于目标语法树生成源程序对应的目标代码;基于预设内存分配算法确定各个分词的第一内存地址,并对各个第一内存地址进行内存优化;基于内存优化后的所有第一内存地址对所述目标代码进行编译,从而得到源程序的编译结果。如此,采用本申请实施例提供的结构化文本编程语言的编译方法能够实现对结构化文本编程语言的直接编译,而无需将结构化文本编程语言转成C语言之后再对其进行编译,从而能够节省出将结构化文本编程语言转成C语言的转换时间,提高结构化文本编程语言的编译效率。It can be seen from the above that the method for compiling a structured text programming language provided by the embodiment of the present application divides the source program to be compiled into one or more word segmentations based on preset lexical rules, and then executes each word segmentation based on preset grammatical rules. Grammar analysis, and determine the grammatically correct target syntax tree based on the analyzed grammatically correct word segmentation; generate the target code corresponding to the source program based on the target syntax tree; determine the first memory address of each word segmentation based on the preset memory allocation algorithm, and assign performing memory optimization on the first memory address; compiling the target code based on all first memory addresses after memory optimization, so as to obtain a compilation result of the source program. In this way, the method for compiling the structured text programming language provided by the embodiment of the present application can realize the direct compilation of the structured text programming language, without converting the structured text programming language into C language and then compiling it, thereby enabling The conversion time for converting the structured text programming language into the C language is saved, and the compilation efficiency of the structured text programming language is improved.
基于上述实施例提供的结构化文本编程语言的编译方法,本申请实施例进一步给出实现上述方法实施例的结构化文本编程语言的编译器,请参阅图6,图6为本申请实施例提供的一种结构化文本编程语言的编译器的结构示意图。如图6所示,该结构化文本编程语言的编译器60可以包括第一分割单元61、第一确定单元62、第一生成单元63、第二确定单元64以及第一编译单元65。Based on the compilation method of the structured text programming language provided by the above embodiment, the embodiment of the present application further provides a compiler for implementing the structured text programming language of the above method embodiment, please refer to Fig. 6, which is provided by the embodiment of the present application A schematic diagram of the structure of a compiler for a structured text programming language. As shown in FIG. 6 , the structured text
其中:in:
第一分割单元61用于基于预设词法规则将待编译的源程序分割为一个或多个分词。The
第一确定单元62用于基于预设语法规则对各个所述分词进行语法分析,并基于分析出的语法正确的所述分词确定语法正确的目标语法树。The first determining
第一生成单元63用于基于所述目标语法树生成所述源程序对应的目标代码。The
第二确定单元64用于基于预设内存分配算法确定所述各个所述分词的第一内存地址,并对各个所述第一内存地址进行内存优化;The
第一编译单元65用于基于内存优化后的所有所述第一内存地址对所述目标代码进行编译,得到所述源程序的编译结果。The
可选的,所述分词的分词类型包括注释符号、标识符号、关键字、变量、字符串、数值文字、四则运算符号、数组符号和/或结束符号;对应的,第一分割单元61可以包括词法分析单元和第二分割单元。其中:Optionally, the word segmentation type of the word segmentation includes comment symbols, identifier symbols, keywords, variables, character strings, numerical literals, arithmetic symbols, array symbols, and/or end symbols; correspondingly, the
词法分析单元用于基于预设识别函数对所述源程序进行词法分析;所述预设识别函数是基于预设词法规则构建的。The lexical analysis unit is used to perform lexical analysis on the source program based on a preset recognition function; the preset recognition function is constructed based on preset lexical rules.
第二分割单元用于基于所述词法分析的结果,将所述源程序分割为一个或多个分词类型包括注释符号、标识符号、关键字、变量、数值文字、四则运算符号、数组符号和/或结束符号的分词。The second division unit is used to divide the source program into one or more word segmentation types based on the result of the lexical analysis, including comment symbols, identifier symbols, keywords, variables, numerical literals, four arithmetic symbols, array symbols and/or or the participle of the ending symbol.
可选的,第一确定单元62可以还包括第二生成单元和第三确定单元。其中:Optionally, the first determining
第二生成单元用于基于语法正确的所述分词生成第一语法树。The second generation unit is used to generate the first syntax tree based on the grammatically correct word segmentation.
第三确定单元用于对所述第一语法树进行语义分析,并基于所述语义分析的结果确定所述目标语法树。The third determining unit is configured to perform semantic analysis on the first syntax tree, and determine the target syntax tree based on a result of the semantic analysis.
可选的,第三确定单元可以还包括第四确定单元、第一更新单元以及第五确定单元。其中:Optionally, the third determining unit may further include a fourth determining unit, a first updating unit, and a fifth determining unit. in:
第四确定单元用于基于预设语义分析函数对所述第一语法树进行类型检查,确定所述第一语法树中语义错误的分词和语义正确的分词。The fourth determining unit is configured to perform a type check on the first syntax tree based on a preset semantic analysis function, and determine semantically incorrect word segmentation and semantically correct word segmentation in the first syntax tree.
第一更新单元用于基于所述第一语法树中所有语义正确的所述分词,对所述第一语法树中的各个分词对应的数据类型进行更新。The first updating unit is configured to update the data type corresponding to each participle in the first grammatical tree based on all the semantically correct participles in the first grammatical tree.
第五确定单元用于基于所述第一语法树中所有语义正确的所述分词和更新后的各个所述分词对应的数据类型,确定所述目标语法树。The fifth determining unit is configured to determine the target syntax tree based on all the semantically correct word segments in the first syntax tree and the updated data types corresponding to each of the word segments.
可选的,第三确定单元可以还包括第一修正单元。Optionally, the third determining unit may further include a first correcting unit.
第一修正单元用于对所述第一语法树中语义错误的所述分词进行语义修正,将语义错误的所述分词修正为语义正确的分词。The first correction unit is configured to perform semantic correction on the word segmentation with semantic error in the first syntax tree, and correct the word segmentation with semantic error into a word segmentation with correct semantics.
可选的,第二确定单元64可以还包括第六确定单元、第七确定单元以及第八确定单元。其中:Optionally, the second determining
第六确定单元用于确定各个所述分词的第一数据类型;所述第一数据类型包括直接指定地址类型和非直接指定地址类型。The sixth determination unit is used to determine the first data type of each word segment; the first data type includes a directly specified address type and an indirect specified address type.
第七确定单元用于将各个所述第一数据类型为所述直接指定地址类型的第一分词的预设内存地址分别确定为各个所述第一分词的第一内存地址;所述预设内存地址为预先基于所述静态内存分配算法为各个所述分词分配的内存地址。The seventh determining unit is used to determine the preset memory addresses of the first participle whose first data type is the directly specified address type respectively as the first memory address of each of the first participle; the preset memory The address is a memory address pre-allocated for each of the word segmentations based on the static memory allocation algorithm.
第八确定单元用于基于所述动态内存分配算法,确定各个所述第一数据类型为所述非直接指定地址类型的第二分词的第一内存地址。The eighth determining unit is configured to determine the first memory addresses of the second participles where each of the first data types is the non-directly specified address type based on the dynamic memory allocation algorithm.
可选的,第八确定单元可以还包括第九确定单元、第十确定单元以及第十一确定单元。其中:Optionally, the eighth determining unit may further include a ninth determining unit, a tenth determining unit, and an eleventh determining unit. in:
第九确定单元用于确定各个所述第二分词的第二数据类型;所述第二数据类型包括直接表示变量类型和非直接表示变量类型。The ninth determining unit is configured to determine a second data type of each of the second participles; the second data type includes a direct representation variable type and an indirect representation variable type.
第十确定单元用于基于各个所述第二数据类型为所述直接表示变量类型的第二分词的内存地址标记符分别确定对应的所述第二分词的第一内存地址;每个所述内存地址标记符分别对应所述第一内存地址中的一个不同的区域。The tenth determination unit is configured to respectively determine the corresponding first memory address of the second word segmentation based on each of the second data types being the memory address marker of the second word segmentation directly representing the variable type; each of the memory The address markers respectively correspond to a different area in the first memory address.
第十一确定单元用于基于各个所述第二数据类型为非直接表示变量类型的第二分词的分词类型分别确定对应的所述第二分词的第一内存地址;每个所述分词类型对应所述第一内存地址中的一个不同的区域。The eleventh determining unit is used to respectively determine the corresponding first memory address of the second word segmentation based on the word segmentation types of the second word segmentation that each of the second data type is not directly representing the variable type; each of the word segmentation types corresponds to A different region within the first memory address.
需要说明的是,上述单元之间的信息交互、执行过程等内容,由于与本申请方法实施例基于同一构思,其具体功能及带来的技术效果,具体可参照方法实施例部分,此处不再赘述。It should be noted that, since the information interaction and execution process between the above units are based on the same idea as the method embodiment of the present application, its specific functions and technical effects can refer to the method embodiment part for details, and will not be discussed here. Let me repeat.
请参阅图7,图7为本申请实施例提供的一种电子设备的结构示意图。如图7所示,本实施例提供的电子设备7可以包括:处理器70、存储器71以及存储在存储器71中并可在处理器70上运行的计算机程序72。例如结构化文本编程语言的编译方法对应的程序。处理器70执行计算机程序72时实现上述应用于结构化文本编程语言的编译方法实施例中的步骤,例如图1所示的S101~S105、图2所示的S1011~S1012、图3中的S1021~S1022以及图5所示的S1041~S1043。或者,处理器70执行计算机程序72时实现上述电子设备7对应的实施例中各模块/单元的功能,例如图6所示的单元61~65的功能。Please refer to FIG. 7 . FIG. 7 is a schematic structural diagram of an electronic device provided in an embodiment of the present application. As shown in FIG. 7 , the
示例性的,计算机程序72可以被分割成一个或多个模块/单元,一个或者多个模块/单元被存储在存储器71中,并由处理器70执行,以完成本申请。一个或多个模块/单元可以是能够完成特定功能的一系列计算机程序指令段,该指令段用于描述计算机程序72在电子设备7中的执行过程。例如,计算机程序72可以被分割成第一分割单元、第一确定单元、第一生成单元、第二确定单元以及第一编译单元,各单元的具体功能请参阅图6对应的实施例中的相关描述,此处不赘述。Exemplarily, the
本领域技术人员可以理解,图7仅仅是电子设备7的示例,并不构成对电子设备7的限定,可以包括比图示更多或更少的部件,或者组合某些部件,或者不同的部件。Those skilled in the art can understand that FIG. 7 is only an example of the
处理器70可以是中央处理单元(central processing unit,CPU),还可以是其他通用处理器、数字信号处理器(digital signal processor,DSP)、专用集成电路(application specific integrated circuit,ASIC)、现成可编程门阵列(field-programmable gate array,FPGA)或者其他可编程逻辑器件、分立门或者晶体管逻辑器件、分立硬件组件等。通用处理器可以是微处理器或者该处理器也可以是任何常规的处理器等。The
存储器71可以是电子设备7的内部存储单元,例如电子设备7的硬盘或内存。存储器71也可以是电子设备7的外部存储设备,例如电子设备7上配备的插接式硬盘、智能存储卡(smart media card,SMC)、安全数字(secure digital,SD)卡或闪存卡(flash card)等。进一步地,存储器71还可以既包括电子设备7的内部存储单元也包括外部存储设备。存储器71用于存储计算机程序以及电子设备所需的其他程序和数据。存储器71还可以用于暂时地存储已经输出或者将要输出的数据。The
所属领域的技术人员可以清楚地了解到,为了描述的方便和简洁,仅以上述各功能单元的划分进行举例说明,实际应用中,可以根据需要而将上述功能分配由不同的功能单元完成,即将结构化文本编程语言的编译器的内部结构划分成不同的功能单元,以完成以上描述的全部或者部分功能。实施例中的各功能单元可以集成在一个处理单元中,也可以是各个单元单独物理存在,也可以两个或两个以上单元集成在一个单元中,上述集成的单元既可以采用硬件的形式实现,也可以采用软件功能单元的形式实现。另外,各功能单元的具体名称也只是为了便于相互区分,并不用于限制本申请的保护范围。上述系统中单元的具体工作过程,可以参考前述方法实施例中的对应过程,在此不再赘述。Those skilled in the art can clearly understand that for the convenience and brevity of description, only the division of the above-mentioned functional units is used as an example for illustration. In practical applications, the above-mentioned function allocation can be completed by different functional units according to needs. The internal structure of the compiler of the structured text programming language is divided into different functional units to complete all or part of the functions described above. Each functional unit in the embodiment can be integrated into one processing unit, or each unit can exist separately physically, or two or more units can be integrated into one unit, and the above-mentioned integrated units can be implemented in the form of hardware , can also be implemented in the form of software functional units. In addition, the specific names of the functional units are only for the convenience of distinguishing each other, and are not used to limit the protection scope of the present application. For the specific working process of the units in the above system, reference may be made to the corresponding process in the foregoing method embodiments, and details are not repeated here.
本申请实施例还提供了一种计算机可读存储介质,该计算机可读存储介质中存储有计算机程序,该计算机程序被处理器执行时可实现上述各个方法实施例中的步骤。The embodiment of the present application also provides a computer-readable storage medium, where a computer program is stored in the computer-readable storage medium, and when the computer program is executed by a processor, the steps in the foregoing method embodiments can be implemented.
本申请实施例提供了一种计算机程序产品,当计算机程序产品在终端设备上运行时,使得终端设备实现上述各个方法实施例中的步骤。An embodiment of the present application provides a computer program product, which enables the terminal device to implement the steps in the foregoing method embodiments when the computer program product is run on the terminal device.
在上述实施例中,对各个实施例的描述都各有侧重,某个实施例中没有详述或记载的部分,可以参照其它实施例的相关描述。In the above-mentioned embodiments, the descriptions of each embodiment have their own emphases, and for parts that are not detailed or recorded in a certain embodiment, reference may be made to relevant descriptions of other embodiments.
本领域普通技术人员可以意识到,结合本文中所公开的实施例描述的各示例的单元及算法步骤,能够以电子硬件、或者计算机软件和电子硬件的结合来实现。这些功能究竟以硬件还是软件方式来执行,取决于技术方案的特定应用和设计约束条件。专业技术人员可以对每个特定的应用来使用不同方法来实现所描述的功能,但是这种实现不应认为超出本申请的范围。Those skilled in the art can appreciate that the units and algorithm steps of the examples described in conjunction with the embodiments disclosed herein can be implemented by electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are executed by hardware or software depends on the specific application and design constraints of the technical solution. Skilled artisans may use different methods to implement the described functions for each specific application, but such implementation should not be regarded as exceeding the scope of the present application.
以上所述实施例仅用以说明本申请的技术方案,而非对其限制;尽管参照前述实施例对本申请进行了详细的说明,本领域的普通技术人员应当理解:其依然可以对前述各实施例所记载的技术方案进行修改,或者对其中部分技术特征进行等同替换;而这些修改或者替换,并不使相应技术方案的本质脱离本申请各实施例技术方案的精神和范围,均应包含在本申请的保护范围之内。The above-described embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them; although the present application has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that: it can still implement the foregoing embodiments Modifications to the technical solutions described in the examples, or equivalent replacements for some of the technical features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the various embodiments of the application, and should be included in the Within the protection scope of this application.
Claims (10)
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202310167261.1A CN116360788A (en) | 2023-02-17 | 2023-02-17 | Compiling method, compiler and electronic device for structured text programming language |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202310167261.1A CN116360788A (en) | 2023-02-17 | 2023-02-17 | Compiling method, compiler and electronic device for structured text programming language |
Publications (1)
Publication Number | Publication Date |
---|---|
CN116360788A true CN116360788A (en) | 2023-06-30 |
Family
ID=86932253
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202310167261.1A Pending CN116360788A (en) | 2023-02-17 | 2023-02-17 | Compiling method, compiler and electronic device for structured text programming language |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN116360788A (en) |
Cited By (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN118394347A (en) * | 2024-06-21 | 2024-07-26 | 湖南云畅网络科技有限公司 | Multi-terminal source code compiling generation method and system for low code platform |
WO2025060641A1 (en) * | 2023-09-21 | 2025-03-27 | 南京南瑞继保电气有限公司 | Method and apparatus for converting object-oriented structured code, and electronic device |
Citations (8)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
WO1992015941A1 (en) * | 1991-02-27 | 1992-09-17 | Digital Equipment Corporation | Method of constructing a constant-folding mechanism in a multilanguage optimizing compiler |
CN1635482A (en) * | 2003-12-29 | 2005-07-06 | 北京中视联数字系统有限公司 | A memory management method for embedded system |
CN104267999A (en) * | 2014-09-26 | 2015-01-07 | 浙江中控技术股份有限公司 | Method and device for compiling control program |
CN105302737A (en) * | 2015-11-24 | 2016-02-03 | 浪潮(北京)电子信息产业有限公司 | Memory allocation management method and memory allocation management system |
CN110825384A (en) * | 2019-10-28 | 2020-02-21 | 国电南瑞科技股份有限公司 | ST language compiling method, system and compiler based on LLVM |
CN111488154A (en) * | 2020-04-23 | 2020-08-04 | 北京东土科技股份有限公司 | ST language source code compiling method, device, computer equipment and medium |
CN112835323A (en) * | 2020-12-31 | 2021-05-25 | 深圳市雷赛控制技术有限公司 | Programmable logic control language compiling method and device |
CN114780382A (en) * | 2022-03-18 | 2022-07-22 | 南京南瑞继保电气有限公司 | Secure redundant compilation operation method, computer device and readable storage medium |
-
2023
- 2023-02-17 CN CN202310167261.1A patent/CN116360788A/en active Pending
Patent Citations (8)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
WO1992015941A1 (en) * | 1991-02-27 | 1992-09-17 | Digital Equipment Corporation | Method of constructing a constant-folding mechanism in a multilanguage optimizing compiler |
CN1635482A (en) * | 2003-12-29 | 2005-07-06 | 北京中视联数字系统有限公司 | A memory management method for embedded system |
CN104267999A (en) * | 2014-09-26 | 2015-01-07 | 浙江中控技术股份有限公司 | Method and device for compiling control program |
CN105302737A (en) * | 2015-11-24 | 2016-02-03 | 浪潮(北京)电子信息产业有限公司 | Memory allocation management method and memory allocation management system |
CN110825384A (en) * | 2019-10-28 | 2020-02-21 | 国电南瑞科技股份有限公司 | ST language compiling method, system and compiler based on LLVM |
CN111488154A (en) * | 2020-04-23 | 2020-08-04 | 北京东土科技股份有限公司 | ST language source code compiling method, device, computer equipment and medium |
CN112835323A (en) * | 2020-12-31 | 2021-05-25 | 深圳市雷赛控制技术有限公司 | Programmable logic control language compiling method and device |
CN114780382A (en) * | 2022-03-18 | 2022-07-22 | 南京南瑞继保电气有限公司 | Secure redundant compilation operation method, computer device and readable storage medium |
Non-Patent Citations (4)
Title |
---|
佚名: "操作系统学习笔记-11:内存分配(一):连续分配", pages 1 - 9, Retrieved from the Internet <URL:《https://cloud.tencent.com/developer/article/1624110》> * |
冯博琴: "《软件技术基础》", 31 July 2000, 人民邮电出版社, pages: 123 - 129 * |
李雨真: "结构化文本语言开发工具的设计与实现", 《中国优秀硕士学位论文全文数据库 (信息科技辑)》, 31 January 2020 (2020-01-31), pages 138 - 777 * |
郭黎明等: "《操作系统》", 30 June 2006, 北京工业大学出版社, pages: 78 - 81 * |
Cited By (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
WO2025060641A1 (en) * | 2023-09-21 | 2025-03-27 | 南京南瑞继保电气有限公司 | Method and apparatus for converting object-oriented structured code, and electronic device |
CN118394347A (en) * | 2024-06-21 | 2024-07-26 | 湖南云畅网络科技有限公司 | Multi-terminal source code compiling generation method and system for low code platform |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN116360788A (en) | Compiling method, compiler and electronic device for structured text programming language | |
CN108139891B (en) | Method and system for generating recommendations to correct undefined tag errors | |
US9753705B2 (en) | Conditional compilation of bytecode | |
CN111324396B (en) | A blockchain smart contract execution method, device and equipment | |
JP6241352B2 (en) | Compiler, compiling method, and compiling device | |
CN107924326A (en) | The moving method of updated type is covered | |
JPH06501579A (en) | Method and apparatus for expressing effects and dependencies of programming operations | |
CN112558984A (en) | Code compiling method and device, electronic equipment and server | |
CN112860233A (en) | Target syntax tree generation method and related equipment | |
CN114327477A (en) | Intelligent contract execution method and device, electronic device and storage medium | |
CN116627429A (en) | Assembly code generation method and device, electronic equipment and storage medium | |
CN117931204A (en) | Method and apparatus for implementing built-in function API translations across ISAs | |
CN112948400A (en) | Database management method, database management device and terminal equipment | |
CN111796832B (en) | Hot patch file generation method, device, equipment and storage medium | |
CN107818100B (en) | SQL statement execution method and device | |
CN118378592B (en) | Large model fine tuning method and device based on formula learning and storage medium | |
CN118550543B (en) | A mixed language recognition method and system | |
CN113535178B (en) | Code package reference method and device | |
CN117519665B (en) | Model-driven assembler automatic generation method and device | |
JP2011123719A (en) | Language processing system, language processing method and language-processing program | |
CN118605846A (en) | A method, system, device and medium for generating and loading software data | |
CN119201126A (en) | Programming language compilation method, device, readable storage medium and terminal device | |
CN115080591A (en) | Database language correction method, device, computer terminal and storage medium | |
CN114879975A (en) | A code compilation method, device and electronic device | |
WO2024198779A1 (en) | Method and apparatus for marking operation type of bytecode, and electronic device |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
RJ01 | Rejection of invention patent application after publication |
Application publication date: 20230630 |
|
RJ01 | Rejection of invention patent application after publication |