Dynamic programming language reconstruction method and device

A dynamic programming and programming language technology, applied in the field of computer programs, can solve problems such as lack of parameters, type errors, hidden dangers of code stability, etc., and achieve the effect of improving code quality, maintaining compatibility, and reducing maintenance costs

Pending Publication Date: 2021-06-11
北京长亭未来科技有限公司
0 Cites 0 Cited by

AI-Extracted Technical Summary

Problems solved by technology

[0003] Lua is a very simple programming language, but it also has some disadvantages. For example, the Lua data structure is relatively primitive. For example, there are no map, struct or array types in other common programming languages, but a data structure called table.
In Lua code, passing a piece of data does not know exactly what type of data it is; Lua syntax is too loose, for example, a function definition accep...
the structure of the environmentally friendly knitted fabric provided by the present invention; figure 2 Flow chart of the yarn wrapping machine for environmentally friendly knitted fabrics and storage devices; image 3 Is the parameter map of the yarn covering machine
View more

Abstract

The embodiment of the invention discloses a dynamic programming language reconstruction method and device, and the method comprises the steps: redefining the grammar of an original dynamic programming language to obtain a new dynamic programming language; performing grammar check on the source program based on the new dynamic programming language. According to the method, the source program of the new dynamic programming language passing the grammar check is generated into the source program which is interpreted and executed by the original dynamic programming language interpreter, the new language grammar is defined, the code maintenance cost is reduced, and the code quality is improved.

Application Domain

Technology Topic

Dynamic programming languagesReconstruction method +5

Image

  • Dynamic programming language reconstruction method and device
  • Dynamic programming language reconstruction method and device
  • Dynamic programming language reconstruction method and device

Examples

  • Experimental program(1)

Example Embodiment

[0041] In order to make those skilled in the art better understand the solutions of the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are only The embodiments are part of the present application, but not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative work shall fall within the scope of protection of the present application.
[0042] like figure 1 As shown, a method for refactoring a dynamic programming language provided in an embodiment of the present invention includes:
[0043] Step S11, redefine the grammar of the original dynamic programming language to obtain a new dynamic programming language;
[0044] Step S12, performing syntax check on the source program based on the new dynamic programming language;
[0045] In step S32, the source program of the new dynamic programming language that has passed the syntax check is generated to be interpreted and executed by the original dynamic programming language interpreter.
[0046] As an embodiment of the present application, step S11 specifically includes:
[0047] Step S111, based on the grammar of the original dynamic programming language, adding a part of the grammar of the static programming language to form the grammar of the new dynamic programming language;
[0048] Step S112, describe the grammar of the new dynamic programming language through an open-source syntax analyzer framework to obtain the new dynamic programming language.
[0049] In the embodiments of this application, the grammar structure of the new dynamic programming language needs to be defined first. We use antlr grammar rules to describe it. During the definition process, the grammar of the original dynamic programming language is compatible, and the grammar of some static programming languages ​​is added to form The new dynamic programming language, the application describes the grammar of the new dynamic programming language through the open source syntax analyzer framework, and obtains the new dynamic programming language.
[0050] In this application, the syntax of some static programming languages ​​is added, including,
[0051] Numeric types, string types, boolean types, array types, dictionary types and composite and function types.
[0052] Among them, the number type is defined as number in the grammar, which corresponds to the number type in the Lua language, localexample:number=1
[0053]Among them, the string type is defined as string in the grammar, which corresponds to the string type in the Lua language, localexample:string="a".
[0054] Among them, the Boolean type is boolean in the grammar definition, which corresponds to the Boolean type in the Lua language, localexample:boolean=false.
[0055] Among them, the array type is {T} in the grammar definition, which corresponds to the table type in the Lua language, localexample:{number}={1,2,3}.
[0056] Among them, the dictionary type is {T:T} in the grammar definition, which corresponds to the table type in the Lua language, localexample:{string:number}={"key":"value"}.
[0057] Among them, the composite type is defined as record in the grammar, which corresponds to the table type in the Lua language, and each field of the record has its own type.
[0058] local type example=record
[0059] a:string
[0060] b:number
[0061] end
[0062] In the Lua language, there is no clear distinction between array types, dictionary types and composite types, which brings inconvenience to development and use. This application adds these types to facilitate programmers to distinguish the role of variables in the development process, and to facilitate the compiler to automatically check type definitions. Overall code readability is improved and maintenance costs are reduced.
[0063] Among them, the function type is defined as function in the grammar, which corresponds to the function type in the Lua language. In TypedLua, the function type needs to mark the types of parameters and return values.
[0064] local function example(arg1:number,arg2:string):string,number
[0065] return arg2,arg1
[0066] end
[0067] In the example of the present application, step S12, the syntax check of the source program based on the new dynamic programming language, including:
[0068] Step S121, for the traversed and parsed syntax tree, determine the syntax type of each node in the syntax tree;
[0069] Step S122, calling the corresponding check rule for the grammar type of each node.
[0070] Based on the above syntax definition and type definition, the code needs to be type checked to find possible errors in the code. The main check types are: basic type check; parameter return value matching check; field module existence check.
[0071] The basic process is to traverse the parsed syntax tree, determine the syntax type of each node in the syntax tree, and apply relevant inspection rules.
[0072] Among them, the basic type check includes using syntax parsing to obtain a syntax tree, and traversing the syntax tree to check whether the syntax type is correct, and if the syntax type is incorrect, the check fails. Taking the local example:string=1 code as an example, the syntax tree can be parsed using the above syntax definition, such as Figure 4 As shown, when traversing the syntax tree, it is found that this is an assignment statement, which assigns 1 of type number to an example whose type is defined as string. This is not allowed by type checking and needs to be processed with error reporting.
[0073] Wherein, the parameter return value matching check includes using syntax parsing to obtain a syntax tree, traversing the syntax tree, and checking function definitions and function calls in the syntax tree.
[0074] The source program sample is as follows
[0075] local function example(arg1:number,arg2:string):string,number
[0076] return arg1,arg2
[0077] end
[0078] example("",1)
[0079] syntax tree such as Figure 5 As shown, when traversing the syntax tree, it is found that it contains function definitions and function call statements.
[0080] The checking of function definitions and function statement calls in the syntax tree includes,
[0081] For function definitions, check the number of function parameters and parameter types, the number of function return values ​​and return value types, if the number of parameters does not match, and/or the parameter types do not match; and/or the number of return values ​​does not match, and/ Or the return value type does not match, the check fails.
[0082] For a function call, the function parameter number and parameter type are checked, and if the parameter number does not match, and/or the parameter type does not match, the check fails.
[0083] Specifically, for the function definition, it is necessary to check the matching of the number and type of function parameters, and the number and type of the function return value. For example, in this example, the function return value is defined as string, number but the return value is return arg1, arg2, because it is known that arg1 , The type of arg2 is defined as number, the return value type of string does not match, and the check fails.
[0084] For function calls, you need to check the number and types of function parameters. For example, in this example, the function parameters are defined as number, string, but the function parameters are "", 1. The number of function parameters is inconsistent, and the type check fails.
[0085] Among them, the field module existence check includes using syntax parsing to obtain a syntax tree, and traversing the syntax tree to check whether the field exists. If it does not exist, the check fails.
[0086] The source program sample is as follows
[0087] local type example=record
[0088] a:string
[0089] end
[0090] local x:example={}
[0091] print(b.f)
[0092] syntax tree such as Image 6 As shown, when traversing the syntax tree, it is found that it contains a record fetching field statement. For the record fetching field statement, it is necessary to check whether the field exists. For example, in this example, the field name is f, but it does not exist in the examplerecord, and the check fails.
[0093] As an embodiment of the present application, the whole process is developed into a compiler of the new dynamic programming language, the functions include: checking the grammatical structure; translating the new dynamic programming language into a Lua source program; after the development of the source program code is completed, first use . /compiler check example.tl is used to check the syntax structure. If the syntax structure check fails, the process will be terminated and a specific error will be prompted, and the code will be returned to re-modify; Translated into example.lua source program.
[0094] In this application, the dynamic programming languages ​​are Lua, PHP, Ruby, and Python languages.
[0095] In this application, the static languages ​​are C and C++.
[0096] In a second aspect, the present application also provides a dynamic programming language reconstruction apparatus 700, including:
[0097] A grammar definition module 71, used to redefine the grammar of the original dynamic programming language to obtain a new dynamic programming language;
[0098] Syntax checking module 72, for performing syntax checking on the source program based on the new dynamic programming language;
[0099] The code generation module 73 generates a source program of the new dynamic programming language that has passed the syntax check to be interpreted and executed by the original dynamic programming language interpreter.
[0100] In the embodiments of this application, the grammar structure of the new dynamic programming language needs to be defined first. We use antlr grammar rules to describe it. During the definition process, the grammar of the original dynamic programming language is compatible, and the grammar of some static programming language is added to form New dynamic programming language, the present application describes the syntax of the new dynamic programming language through an open source parser framework, and the open source parser framework is an open source parser that automatically generates a syntax tree according to input and displays it visually.
[0101] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, but not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that: The technical solutions described in the foregoing embodiments can still be modified, or some or all of the technical features thereof can be equivalently replaced; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the technical solutions of the embodiments of the present invention. scope.
the structure of the environmentally friendly knitted fabric provided by the present invention; figure 2 Flow chart of the yarn wrapping machine for environmentally friendly knitted fabrics and storage devices; image 3 Is the parameter map of the yarn covering machine
Login to view more

PUM

no PUM

Description & Claims & Application Information

We can also present the details of the Description, Claims and Application information to help users get a comprehensive understanding of the technical details of the patent, such as background art, summary of invention, brief description of drawings, description of embodiments, and other original content. On the other hand, users can also determine the specific scope of protection of the technology through the list of claims; as well as understand the changes in the life cycle of the technology with the presentation of the patent timeline. Login to view more.
the structure of the environmentally friendly knitted fabric provided by the present invention; figure 2 Flow chart of the yarn wrapping machine for environmentally friendly knitted fabrics and storage devices; image 3 Is the parameter map of the yarn covering machine
Login to view more

Similar technology patents

Adjusting mechanism of electrically tunable antenna

InactiveCN106252883AQuick and easy installation and removalReduce maintenance costsAntennasElectric machineRisk stroke
Owner:MOBILE ANTENNA TECH SHENZHEN +2

Classification and recommendation of technical efficacy words

  • Reduce maintenance costs
  • Improve code quality

Method for rapidly developing BI platform based on EXTJS

Owner:上海吉贝克信息技术有限公司

Android API application specification-based automatic code quality evaluation and optimization method

ActiveCN106126412AReduce misuse and misuseImprove code qualitySoftware testing/debuggingApplication softwareQuality assessment
Owner:INST OF SOFTWARE - CHINESE ACAD OF SCI

Software debugging management method, device and system and storage medium

PendingCN110109830AImprove code qualityPromotionSoftware testing/debuggingUser codeSoftware debugging
Owner:深圳行云创新科技有限公司

Visual analysis and management method and system for JavaScript memory, equipment and storage medium

PendingCN113688189AReduce learning costs and labor costsImprove code qualityNatural language data processingSoftware testing/debuggingRelational graphDevelopment team
Owner:济南浪潮数据技术有限公司
Who we serve
  • R&D Engineer
  • R&D Manager
  • IP Professional
Why Eureka
  • Industry Leading Data Capabilities
  • Powerful AI technology
  • Patent DNA Extraction
Social media
Try Eureka
PatSnap group products