CN117992183A - Event response method, system, electronic equipment and storage medium - Google Patents

Event response method, system, electronic equipment and storage medium Download PDF

Info

Publication number
CN117992183A
CN117992183A CN202410117646.1A CN202410117646A CN117992183A CN 117992183 A CN117992183 A CN 117992183A CN 202410117646 A CN202410117646 A CN 202410117646A CN 117992183 A CN117992183 A CN 117992183A
Authority
CN
China
Prior art keywords
description information
value description
event
value
virtual machine
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
Application number
CN202410117646.1A
Other languages
Chinese (zh)
Inventor
杨清广
谢一铭
李日璐
王春华
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Guangdong Youteyun Technology Co ltd
Original Assignee
Guangdong Youteyun Technology Co ltd
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by Guangdong Youteyun Technology Co ltd filed Critical Guangdong Youteyun Technology Co ltd
Priority to CN202410117646.1A priority Critical patent/CN117992183A/en
Publication of CN117992183A publication Critical patent/CN117992183A/en
Pending legal-status Critical Current

Links

Landscapes

  • Devices For Executing Special Programs (AREA)

Abstract

The application discloses an event response method, an event response system, electronic equipment and a storage medium, and belongs to the technical field of computer technology. The event response method comprises the following steps: receiving a standard source program input by a user; the standard source program comprises value description information, wherein the value description information is used for restricting the value range of the variable and/or the function parameter; generating a data dictionary and a grammar tree corresponding to the standard source program based on the value description information; converting the grammar tree into an object code, and packaging the object code and the data dictionary to obtain a virtual machine byte code so that a standard virtual machine loads the virtual machine byte code; if the operation event of the user is monitored, executing an instruction corresponding to the operation event by using the standard virtual machine under the condition that the value description information is met, so as to respond to the operation event. The application can reduce the complexity of the control statement of the data value range and improve the event response efficiency.

Description

Event response method, system, electronic equipment and storage medium
Technical Field
The present application relates to the field of computer technologies, and in particular, to an event response method, system, electronic device, and storage medium.
Background
In order to shorten the development period and quickly realize the business function, a user language is generally designed to interact with a computer. User language is commonly used to write programs to effect responses to specific events; for example, if an induction cooker operating mode adjustment event is detected, the current power of the induction cooker may be changed; if a fan gear adjustment event is detected, the current rotational speed of the motor is changed.
In the related art, a user language generally uses a data type and control flow statement to control a data value range, but the statement for controlling the data value range is long, the writing complexity is high, and the response efficiency to an event after the program is run is low.
Therefore, how to reduce the complexity of the data value range control statement and improve the event response efficiency is a technical problem that needs to be solved by those skilled in the art.
Disclosure of Invention
The application aims to provide an event response method, an event response system, electronic equipment and a storage medium, which can reduce the complexity of a data value range control statement and improve the event response efficiency.
In order to solve the above technical problems, the present application provides an event response method, including:
Receiving a standard source program input by a user; the standard source program comprises value description information, wherein the value description information is used for restricting the value range of the variable and/or the function parameter;
Generating a data dictionary and a grammar tree corresponding to the standard source program based on the value description information; wherein, the value description information is loaded in the data dictionary, and nodes in the grammar tree accord with the value description information;
Converting the grammar tree into an object code, and packaging the object code and the data dictionary to obtain a virtual machine byte code so that a standard virtual machine loads the virtual machine byte code; wherein, the virtual machine byte code comprises a data table corresponding to the value description information;
If the operation event of the user is monitored, executing an instruction corresponding to the operation event by using the standard virtual machine under the condition that the value description information is met, so as to respond to the operation event.
Optionally, generating the data dictionary and the syntax tree corresponding to the standard source program based on the value description information includes:
generating the data dictionary according to the contents of a variable table, a constant table and a function table in the standard source program;
Generating an initial grammar tree according to statement contents of a statement table in the standard source program;
judging whether the nodes in the initial grammar tree accord with the value description information loaded in the data dictionary or not; if yes, setting the initial grammar tree as the grammar tree corresponding to the standard source program; if not, outputting prompt information of the writing errors of the standard source program.
Optionally, packaging the object code and the data dictionary to obtain a virtual machine bytecode, including:
Packaging the object codes to obtain an event table, an event index table and a logic data table;
Packaging other contents except the value description information in the data dictionary to obtain a variable table, a variable configuration table, a function index table and a function configuration table;
Packaging the value description information in the data dictionary to obtain a variable value description table and/or a function parameter value description table;
And generating the virtual machine byte code according to the packing result of the target code and the packing result of the data dictionary.
Optionally, if the value description information is used for restricting the value range of the variable, executing, by using the standard virtual machine, an instruction corresponding to the operation event under the condition that the value description information is met, including:
converting the operation event into an event list and a variable context; wherein the event list comprises event variable names and event variable values;
inquiring whether the event variable value accords with the value description information according to the event variable name;
if yes, inquiring a target instruction corresponding to the event list, and executing the target instruction by using the standard virtual machine according to the variable context.
Optionally, in the process of executing the target instruction according to the variable context by using the standard virtual machine, the method further includes:
If the variable value operation or the variable assignment operation is detected, stopping executing the target instruction;
judging whether a value corresponding to a value taking operation or a value assigning operation accords with the value description information or not;
If yes, continuing to execute the target instruction;
if not, outputting prompt information of instruction execution errors.
Optionally, the value description information is further used for restricting a value range of a function parameter, and in a process of executing the target instruction according to the variable context by using the standard virtual machine, the method further includes:
If the function calling operation is detected, stopping executing the target instruction;
Judging whether the real parameter combination of the objective function corresponding to the function calling operation accords with the value description information or not;
If yes, continuing to execute the target instruction;
if not, outputting prompt information of instruction execution errors.
Optionally, the value description information includes range type value description information and/or enumeration type value description information.
The application also provides an event response system, which comprises:
the source program receiving module is used for receiving a standard source program input by a user; the standard source program comprises value description information, wherein the value description information is used for restricting the value range of the variable and/or the function parameter;
The compiling module is used for generating a data dictionary and a grammar tree corresponding to the standard source program based on the value description information; wherein, the value description information is loaded in the data dictionary, and nodes in the grammar tree accord with the value description information; the grammar tree is further used for converting the grammar tree into an object code, and packaging the object code and the data dictionary to obtain a virtual machine byte code so that a standard virtual machine loads the virtual machine byte code; wherein, the virtual machine byte code comprises a data table corresponding to the value description information;
And the event response module is used for executing an instruction corresponding to the operation event by using the standard virtual machine under the condition that the value description information is met if the operation event of the user is monitored, so as to realize the response to the operation event.
The present application also provides a storage medium having stored thereon a computer program which, when executed, performs the steps of the event response method described above.
The application also provides an electronic device comprising a memory and a processor, wherein the memory stores a computer program, and the processor realizes the steps executed by the event response method when calling the computer program in the memory.
The application provides an event response method, which comprises the following steps: receiving a standard source program input by a user; the standard source program comprises value description information, wherein the value description information is used for restricting the value range of the variable and/or the function parameter; generating a data dictionary and a grammar tree corresponding to the standard source program based on the value description information; wherein, the value description information is loaded in the data dictionary, and nodes in the grammar tree accord with the value description information; converting the grammar tree into an object code, and packaging the object code and the data dictionary to obtain a virtual machine byte code so that a standard virtual machine loads the virtual machine byte code; wherein, the virtual machine byte code comprises a data table corresponding to the value description information; if the operation event of the user is monitored, executing an instruction corresponding to the operation event by using the standard virtual machine under the condition that the value description information is met, so as to respond to the operation event.
The standard source program received by the method comprises the value description information, and the data dictionary and the grammar tree corresponding to the standard source program can be generated based on the value description information, so that the value description information is loaded in the data dictionary, and the nodes in the grammar tree accord with the constraint of the value description information on the value range of the variable and/or the function parameter. The application converts the grammar tree into the object code, and packages the object code and the data dictionary into the virtual machine byte code so that the standard virtual machine loads the virtual machine byte code. After detecting the operation event of the user, the instruction corresponding to the operation event can be executed under the condition that the constraint of the value description information on the variable and/or the function parameter value range is met, so that the response to the operation event is realized. The application uses the value description information to describe the data value range, and uses the value description information to check the data value during program compiling and running, and lengthy data type and control flow sentences are not required to be used for controlling the data value range, so that the complexity of the control sentences of the data value range can be reduced, and the event response efficiency can be improved. The application also provides an event response system, a storage medium and an electronic device, which have the beneficial effects and are not described in detail herein.
Drawings
For a clearer description of embodiments of the present application, the drawings that are required to be used in the embodiments will be briefly described, it being apparent that the drawings in the following description are only some embodiments of the present application, and other drawings may be obtained according to the drawings without inventive effort for those skilled in the art.
FIG. 1 is a flow chart of an event response method according to an embodiment of the present application;
FIG. 2 is a schematic diagram of a standard source program according to an embodiment of the present application;
FIG. 3 is a schematic diagram of responding to a user operation event according to an embodiment of the present application;
FIG. 4 is a schematic diagram of a language kernel according to an embodiment of the present application;
FIG. 5 is a schematic diagram of a control system for controlling an opening/closing interval and an enumeration range of a data value based on definition according to an embodiment of the present application;
Fig. 6 is a schematic diagram of a syntax tree structure according to an embodiment of the present application.
Detailed Description
For the purpose of making the objects, technical solutions and advantages of the embodiments of the present application more apparent, the technical solutions of 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, and it is apparent that the described embodiments are some embodiments of the present application, but not all embodiments of the present application. All other embodiments, which can be made by those skilled in the art based on the embodiments of the application without making any inventive effort, are intended to be within the scope of the application.
Referring to fig. 1, fig. 1 is a flowchart of an event response method according to an embodiment of the application.
The specific steps may include:
S101: receiving a standard source program input by a user;
The embodiment can be applied to an electronic device with a standard compiler and a standard virtual machine. The user may write a standard source program in a standard language. The standard language is a composition rule of user language standard sentences, and the rule can shield business characteristics among various industries and fields. The standard source program is a data format of standard compiler input data. The standard compiler is used for compiling the standard source program, and specifically, the standard compiler can translate standard language sentences in the standard source program into virtual machine byte codes by combining input data such as a variable table, a function table and the like in the standard source program. A standard virtual machine is a software program that executes logical instructions by parsing virtual machine bytecodes.
Referring to fig. 2, fig. 2 is a schematic diagram of a composition structure of a standard source program according to an embodiment of the present application, where the standard source program may be a standard source program input by a user and including a value description information grammar, and the standard source program includes a variable table, a constant table, a function table and a statement table.
The variable table includes a variable name (e.g., var1, var 2), a data type (e.g., int 32), a unique identification (e.g., key1, key 2), and a value description (e.g., { on=1, off=0 }, (1, 3) }, the constant table includes a constant name (e.g., CONST 1), a data type (int 32), and a constant value (e.g., 1),. The function table includes a function name (e.g., FUNC1, FUNC 2), a parameter list (e.g., int 32), a return value type (e.g., void), unique identifications (e.g., key3 and key 4), and a parameter value description (e.g., (0, 3), [1,4 ]).
The standard source procedure may include value description information for restricting a range of values of the variable and/or the function parameter (i.e., the function input parameter), the value description information including range-type value description information and/or enumeration-type value description information.
Specifically, the range type value description information is used for describing numerical variable or function parameters; the range type value description information uses a mathematical interval representation. The symbols used are half-angle characters, such as [0,9], (0, 9); the range type value description information cannot exceed the range of the data type of the described data.
The enumeration type value description information is used for describing numerical variable or function parameters; the enumeration type value description format is as follows: { alias 1=value 1, alias 2=value 2, …, alias i=value i, … }; the symbols used by the enumeration type value description information are half-angle characters. The alias naming convention is identical to the constant naming convention; aliases may be omitted, such as: { value 1, value 2, …, value i, … }. The enumerated value description cannot be beyond the scope of the data type of the data being described.
The variable is an identifier used to store data. During program execution, variables may store various types of data, such as integers, floating point numbers, strings, boolean values, and the like. Variables are used to store and manipulate data in a program, enabling the program to perform different operations based on the data. The function parameter is a value transferred to the function and is used for influencing the execution behavior of the function. The function parameters may be constants, variables, or expressions, and may be used and modified within the function. The function parameters are used to pass input data to the function, enabling it to perform certain operations and return results.
The range type value description information refers to a section for restricting the value to be a value, for example, [ a, B ], [ a, B), (a, B ] or (a, B); the enumerated value description information refers to a limited number of alternative values of constraint value, such as values selected from C1, C2, C3, C4, and C5.
Combining constraint objects and constraint schemes of the value description information, wherein the value description information can obtain any one or a combination of any of the following types of information:
(1) Range type value description information for restricting a variable value range;
(2) Enumeration type value description information for restricting a variable value range;
(3) Range type value description information for restricting the value range of the function parameter;
(4) And the enumeration type value description information is used for restricting the value range of the function parameter.
S102: generating a data dictionary and a grammar tree corresponding to the standard source program based on the value description information;
The step can generate a corresponding data dictionary (also called symbol table) according to a standard source program, and the value description information is loaded in the data dictionary. This step may generate a syntax tree of node compliance value description information according to a standard source procedure. Specifically, the step may use the value description information in the data dictionary to check the nodes corresponding to the variables and/or the function parameters in the syntax tree, if the check is passed, it is determined that the syntax tree is completely generated, the steps S103 and S104 may be continuously executed, and if the check is not passed, it is determined that the standard source program writes an error.
S103: converting the grammar tree into an object code, and packaging the object code and the data dictionary to obtain a virtual machine byte code so that a standard virtual machine loads the virtual machine byte code;
on the basis of obtaining the grammar tree, the embodiment can perform intermediate code conversion, optimization and object code conversion on the grammar tree to obtain an object code, and further package the object code and a data dictionary to obtain a virtual machine byte code, such as ULC (User Language Compiled, user language compiled product) byte code. In this step, the value description information loaded in the data dictionary may be packed into a specific data area, so that the virtual machine bytecode includes a data table (e.g., a variable value description table and/or a function parameter value description table) corresponding to the value description information.
Specifically, if the value description information is used for restricting the value range of the variable, the virtual machine byte code comprises a variable value description table; if the value description information is used for restricting the value range of the function parameter, the virtual machine byte code comprises a function parameter value description table.
On the basis of obtaining the virtual machine byte codes, the virtual machine byte codes can be input into a standard virtual machine, so that index loading and statement index loading can be carried out by the standard virtual machine. The index loading operation can load related symbol information such as event, variable, function, value description information and the like into a memory in advance; the statement index loading can extract and load IO index information of statement (instruction) data into a memory.
S104: if the operation event of the user is monitored, executing an instruction corresponding to the operation event by using the standard virtual machine under the condition that the value description information is met, so as to respond to the operation event.
Wherein, after the standard virtual machine loads the virtual machine byte code, an event monitoring phase can be entered to monitor the operation event of the user. The operation event may be an event that a user performs an operation on the electronic device, such as gear adjustment, working mode setting, communication data transmission, and the like. After the operation event is monitored, the standard virtual machine can be used for executing the instruction (such as a gear adjustment instruction, a rotation speed adjustment instruction, a data transmission instruction and the like) corresponding to the operation event under the condition that the value description information is met, so that the response to the operation event is realized.
The standard source program received in the embodiment includes value description information, and a data dictionary and a grammar tree corresponding to the standard source program can be generated based on the value description information, so that the value description information is loaded in the data dictionary, and nodes in the grammar tree conform to the constraint of the value description information on the value range of the variable and/or the function parameter. The embodiment converts the grammar tree into the object code, and packages the object code and the data dictionary into the virtual machine byte code so that the standard virtual machine loads the virtual machine byte code. After detecting the operation event of the user, the instruction corresponding to the operation event can be executed under the condition that the constraint of the value description information on the variable and/or the function parameter value range is met, so that the response to the operation event is realized. In this embodiment, the value description information is used to describe the data value range, and the value description information is used to perform data value verification during program compiling and running, so that lengthy data type and control flow statements are not required to be used to control the data value range, and therefore, the complexity of the control statement of the data value range can be reduced, and the event response efficiency is improved.
As a further introduction to the corresponding embodiment of fig. 1, the standard source program includes a variable table, a constant table, a function table and a statement table, and accordingly, the data dictionary and the syntax tree corresponding to the standard source program may be generated by:
Generating the data dictionary according to the contents of a variable table, a constant table and a function table in the standard source program; generating an initial grammar tree according to statement contents of a statement table in the standard source program; judging whether the nodes in the initial grammar tree accord with the value description information loaded in the data dictionary or not; if yes, setting the initial grammar tree as the grammar tree corresponding to the standard source program; if not, outputting prompt information of the writing errors of the standard source program. The data dictionary may be partitioned into blocks for standard source procedures and loaded into symbol and statement tables.
Specifically, the above process may be implemented based on a standard compiler, whose input is a standard source program and whose output is virtual machine bytecode. The embodiment can additionally load the value range of the variable and/or the function parameter into the data dictionary (or called symbol table) according to the value description information on the basis of the original processing process of the data dictionary.
The standard compiler comprises a preprocessor, a lexical analyzer and a grammar analyzer, wherein the lexical analyzer comprises a lexical checker, and the grammar analyzer comprises a grammar checker; the present embodiment may use a preprocessor and a lexical analyzer to perform word segmentation and analysis on the sentence contents in the sentence table so as to generate a corresponding syntax tree, and may also use a syntax analyzer to perform syntax checking on the syntax tree.
The standard compiler may also include a semantic analyzer, which includes a semantic checker. On the basis of the original processing procedure of the semantic analyzer, the embodiment can judge whether the nodes in the initial grammar tree accord with the value description information loaded in the data dictionary by using the semantic analyzer. Specifically, the semantic analyzer may additionally perform value/value range checking on the values of the participating variable assignment/function arguments in the syntax tree by using the related data of the value description information loaded into the data dictionary.
The standard compiler can also comprise an intermediate code generator, a code optimizer and an object code generator; the embodiment can utilize an intermediate code generator, a code optimizer and an object code generator to perform intermediate code conversion, optimization and object code conversion on the grammar tree nodes.
The standard compiler can also comprise a file packer, wherein the file packer is used for assembling data such as grammar tree, data dictionary and the like converted by the target code into a binary byte stream according to a virtual machine byte code specification (such as ULC byte code specification) to obtain the virtual machine byte code. The file packager may also assemble related data of the value description information in the data dictionary into a related data area corresponding to the value description information of the virtual machine bytecode.
Specifically, the process of packaging the object code and the data dictionary into virtual machine byte codes by using a file packager includes: packaging the object codes to obtain an event table, an event index table and a logic data table; packaging other contents except the value description information in the data dictionary to obtain a variable table, a variable configuration table, a function index table and a function configuration table; packaging the value description information in the data dictionary to obtain a variable value description table and/or a function parameter value description table; and generating the virtual machine byte code according to the packing result of the target code and the packing result of the data dictionary.
As a further introduction to the corresponding embodiment of fig. 1, if the value description information is used to constrain the range of values of the variables, the operation event may be responded to by: converting the operation event into an event list and a variable context; wherein the event list comprises event variable names and event variable values; inquiring whether the event variable value accords with the value description information according to the event variable name; if yes, inquiring a target instruction corresponding to the event list, and executing the target instruction by using the standard virtual machine according to the variable context.
Referring to fig. 3, fig. 3 is a schematic diagram of responding to a user operation event provided by an embodiment of the present application, where an electromagnetic oven is used as a host of a standard virtual machine, and after a user operates the electromagnetic oven to adjust power, the host converts the user operation into user input, where the user input includes an event list and a variable context; the event list includes "event variable name: adjusting power "event variable value: 1'; the variable context includes "variable name: power "and" variable value: 2000".
Correspondingly, in the process of executing the target instruction according to the variable context by using the standard virtual machine, if a variable value operation or a variable assignment operation is detected, stopping executing the target instruction; judging whether a value corresponding to a value taking operation or a value assigning operation accords with the value description information or not; if yes, continuing to execute the target instruction so as to complete response to the operation event; if not, outputting prompt information of instruction execution errors.
Further, if the value description information is further used for restricting the value range of the function parameter, in the process of executing the target instruction according to the variable context by using the standard virtual machine, if a function call operation is detected, stopping executing the target instruction; judging whether the real parameter combination of the objective function corresponding to the function calling operation accords with the value description information or not; if yes, continuing to execute the target instruction so as to complete response to the operation event; if not, outputting prompt information of instruction execution errors.
The flow described in the above embodiment is explained below by way of an embodiment in practical application.
In order to shorten the development period and quickly realize the business function, the user language is generally used for programming, and the user language originates from basic logic sentences and can be applied to the power system maintenance environment. In order to identify, compile and execute the user language, the source program specification of the grammar of the matched user language and the byte code specification of the binary operation file are required to be designed, and the matched compiler software and virtual machine software are required to be developed. Referring to fig. 4, fig. 4 is a schematic structural diagram of a language kernel provided by an embodiment of the present application, where the language kernel may process a standard language, and the language kernel includes a CLI (command line) layer, a general layer, and an instruction layer, and further includes a standard compiler, a standard virtual machine, and a micro virtual machine of a software development kit SDK. The standard compiler includes a command line tool CLI and a standard compiler library including standard source program specifications and a compiler core. The standard virtual machine includes a command line tool CLI, a local engine library, and an instruction computation library, the local engine in the local engine library including an enhancement component and a ULC bytecode specification, the instruction calculator in the instruction computation library including an inverse polish instruction specification. The micro-virtual machine includes a command line tool CLI, a local engine library, where the local engine includes a partial enhancement component, and an instruction compute library, where the instruction compute library includes an instruction calculator. The standard virtual machine may perform conditional compilation to the micro-virtual machine.
In the related art, most programming languages use data types for basic value range control of data values. Such as int8 type, the constraint data value cannot be out of the range of [ -128,127 ]. If additional range control is required for the data value, the control is generally implemented by a control flow statement such as an if-else, a switch-case, etc., based on additional statement logic.
Assuming that data a exists and that the value of a is required to be within the range of (1, 3) (greater than 1 and less than or equal to 3), then the statement is required:
if(a>1&&a<=3){do sth}else{error};
If requirement a must take a value between (1, 2,3, 5), then the statement is required:
The data type and control flow statement described above is flexible in the manner of controlling the range of data values, and is the best means for controlling the range of values in almost all programming languages. However, the positioning of the user language is after all a user description language close to the natural language, and the long and professional description with high threshold of the programming language is not coordinated with the user language naturally. In order to fully exert the advantages of low user language threshold and easy use, a simple 'value description' grammar rule for describing the data value range is needed, and a virtual machine operation mechanism for correctly checking the data value according to 'value description' during compiling and operation is needed.
Referring to fig. 5, fig. 5 is a schematic diagram of a system for controlling an opening/closing interval and an enumeration range of a data value based on definition according to an embodiment of the present application, where the system includes a standard source program STD001, a standard compiler SCP01, a ULC byte code (also called ULC file) ULC001 and a standard virtual machine SVM01.
The standard source program is a source program text described by a user language close to natural language, and is input by a standard compiler; the standard compiler is responsible for compiling a standard source program, and is used for translating standard language sentences into virtual machine byte codes by combining input data such as a variable table, a function table and the like in the standard source program; the ULC byte code is a data format of output data of a standard compiler and is one of the byte codes of the virtual machine; a standard virtual machine is a software program that executes logical instructions by parsing the ULC bytecode.
The processing of a standard source program using a standard compiler is described below:
(1) The data dictionary performs analysis tabular analysis on the tabular stored source program text according to standard source program specifications to obtain tabular data: a variable table, a constant table, a function table and a statement table.
The variable table includes a table field (including a variable name, a data type, a unique identifier and a value description) and a line data (such as "var1, int32, key1, { on=1, off=0 }" or "[ var2, int32, key2, (1, 3 ]") the constant table includes a table field ([ constant name, data type, constant value ]) and a line data (such as COSNT, int 32). The function table includes a table field (function name, parameter list, return value type, unique identifier, parameter value description) and a line data (such as FUNC1, "int32, int32", void, key3, "(0, 3)," [1,4] ", or FUNC1,", void, key4, "") the sentence table includes a sentence content, such as "var 1= =1var 2 = =CONST1@FUNC1 (2, 3). FUNC2 ()". The data dictionary loads a data part according to a "standard program". The new parameter value is added and a new parameter value is defined by the "new parameter value is added and a new parameter value is described by the new parameter value.
(2) The SCP002 preprocessor, lexical analyzer and grammar analyzer may parse to form a list of morphemes, construct morphemes into a grammar tree, and perform a complete grammar check. Referring to fig. 6, fig. 6 is a schematic diagram of a syntax tree provided by the embodiment of the present application, the syntax tree shown in fig. 6 is based on statement content "var1 = 1var2 = CONST1@FUNC1 (2, 3): FUNC2 () ]! "constructed.
(3) Semantic analysis by a semantic analyzer can determine the final type (literal quantity, variable, function, operator) of the grammar tree node; the semantic analyzer may perform semantic checks, such as determining whether the node data types on both sides of the operator are compatible, whether the function joins a match with a definition, etc.). The present embodiment can load the value description information of the variable table from the data dictionary. If the constant value is assigned to the variable, searching the value description information of the variable, and judging whether the constant value is in a defined value range. The embodiment may also load parameter value description information of the function table from the data dictionary. If the constant participation function parameters exist, searching parameter value description information of the function, and judging whether the constant value used by each parameter is in a defined value range. The value description check can be completed in the above manner. Taking FUNC1 (2, 3) as an example in the example sentence, since 0 < 2 < 3,1 is less than or equal to 3 and less than or equal to 4, determining that FUNC1 (2, 3) accords with the constraint of the value description information.
(4) After the syntax tree is processed by the intermediate code generator, the code optimizer and the object code generator, each syntax tree node data is replaced by the encoded object code.
(5) The file packager may encode the data of each data region of the data dictionary according to the original specification of the ULC bytecode, including but not limited to "variable table", "constant table", "function table", etc. The file packager writes the data partition into the ULC bytecode according to the original specification of the ULC bytecode, including but not limited to "variable table", "variable configuration table", "function index table", "function configuration table". The file wrapper may also write syntax tree partitions encoded by the "object code generator" into the ULC bytecode, including but not limited to "event table", "event index table", "logical data table", according to the original specification of the ULC bytecode. The file packager loads the value description information of the variable table and the parameter value description information of the function table from the data dictionary according to the ULC byte code new specification, and codes according to the specification. The file wrapper writes the data partition into the ULC byte code according to the original specification of the ULC byte code, including but not limited to a variable value description table and a function parameter value description table. After the file packer completes writing all data, outputting binary byte streams to obtain ULC byte codes shown in table 1.
TABLE 1 composition Structure Table of ULC byte codes
The large file header stores file header data areas of file metadata such as file check codes, file lengths and the like;
The virtual machine file stores a data area of runtime key data including statement instructions, symbol tables (variables, functions, etc.).
The virtual machine file area consists of the following sub-data areas:
the virtual machine file header stores the description statement instruction, the starting position of each data area of the symbol table (variable, function, etc.), and the data area of the metadata of the block length information. The variable table and the variable configuration table store a series of data areas of variable related data such as variable compiling ID, variable type, variable unique identification and the like. A series of data areas of function related data such as function compiling ID, function IO index, parameter entering type, return value type, function unique identification and the like are stored in the function table, the function index table and the function configuration table. A series of data tables of sentence event and sentence index relation are stored in event table and event index table. The logical data table stores a data table of statement instructions corresponding to the syntax tree.
The variable value description table stores a data table of variable compilation IDs and variable value descriptions. The data is serialized using MESSAGEPACK protocol. Variable value description the data contents in the data area are shown in table 2:
table 2 variable value description table
Function parameter value description table: a data table of function compilation IDs and descriptions of the parameter values of the functions is stored. The data is serialized using MESSAGEPACK protocol. The data content of the function parameter value description in the data area is shown in table 3:
table 3 table of description of parameter values of functions
The description of a standard virtual machine is as follows:
The input data of the standard virtual machine is ULC bytecode for ULC index loading and ULC statement index loading. The ULC index loading process can load related symbol information such as event, variable, function, value description and the like into a memory in advance; the ULC statement index loading process loads IO index information of statement (instruction) data into the memory. Event processors in standard virtual machines enter the event { [ event list ], [ variable context ] } snoop phase after completing data loading. The virtual machine at this stage converts the monitored event list into [ < variable, variable value > pair ], and checks the value range of the variable value according to the variable value description in the memory. Only events passing the inspection are compared with the event indexes in the memory; when a virtual machine hits an event index, the logical (statement) data pointed to by the index will be loaded. Taking the statement in the example as an example, assume that the virtual machine listens for an event < var1,1>, the statement "var 1= 1var 2= CONST1@FUNC1 (2, 3): FUNC2 () Σ! "to be loaded by a virtual machine". The virtual machine core engine will perform the execution of a statement, a process also known as statement (instruction) computation. Depending on the instruction content, the instruction may be divided into 7 different instructions (reg_i appearing below represents a register):
the variable value is: reg_1=var;
Variable assignment: var = reg_1;
Constant registering: reg_0=1;
logic and comparison operation: reg_1= reg_2, reg_1 &reg_2, etc.;
Logic, comparison operation and variable assignment register: reg_0= (reg_1= reg_2), etc.;
Function execution: func (reg_1, reg_2, …, reg_n);
Function return register: reg_0=func.
Taking the statement in the example as an example, the statement may be considered as a combination of 12 instructions:
var1==1:
(1)reg_1=var1;
(2)reg_2=1;
(3)reg_1==reg_2;
(4)reg_0=(reg_1==reg_2);
var2==CONST1:
(5)reg_1=var2;
(6)reg_2=CONST1;
(7)reg_1==reg_2;
(8)reg_0=(reg_1==reg_2);
FUNC1(2,3):
(9)reg_1=2;
(10)reg_2=3;
(11)func(reg_1,reg_2);
FUNC2():
(12)func()。
When calculating the variable value and variable assignment type instructions, the virtual machine tries to perform value/assignment operation on the variable context obtained in the monitoring stage. When the virtual machine executes the operation, the virtual machine checks the value range of the variable value according to the variable value description in the memory. Only variables that pass the check are allowed to continue to participate in the instruction calculation.
In computing an instruction of the "function execute" type, the virtual machine will call the actual function according to the function definition. And when the virtual machine executes the operation, checking the value range of the real parameters according to the function 'parameter value description' in the memory. Only function execution through the check is allowed to invoke the actual function and continue to participate in instruction computation.
The embodiment utilizes the value description information to complete the control of the value range of all data values such as variable values, function actual parameters and the like. Compared with the lengthy control flow statement required by the programming language, the embodiment can complete the control of the value range of the data value in the compiling and running processes only by carrying out additional definition of 'value description' when the variables and the functions are defined. The present embodiment configures a lower threshold for the range of values than a highly specialized programming statement description of the programming language. Taking the temperature of the air conditioner as an example, which needs to be set in the range of 16 to 30 degrees, the configurable values describe [16,30]; if it is desired to describe the gear "high/medium/low" of the fan, then { high=1, medium=2, low=3 }; describing the power range of the induction cooker as between 300w and 4kw, the configuration [300,4000] is only needed. The embodiment basically covers most of value control scenes for the range and enumeration value control, and solves the problem of redundancy judgment in the traditional development with lower cost. Compared with the old system, the embodiment belongs to incremental updating, and the system compatibility is not affected by the upgrading of the system.
The embodiment of the application also provides an event response system, which comprises:
the source program receiving module is used for receiving a standard source program input by a user; the standard source program comprises value description information, wherein the value description information is used for restricting the value range of the variable and/or the function parameter;
The compiling module is used for generating a data dictionary and a grammar tree corresponding to the standard source program based on the value description information; wherein, the value description information is loaded in the data dictionary, and nodes in the grammar tree accord with the value description information; the grammar tree is further used for converting the grammar tree into an object code, and packaging the object code and the data dictionary to obtain a virtual machine byte code so that a standard virtual machine loads the virtual machine byte code; wherein, the virtual machine byte code comprises a data table corresponding to the value description information;
And the event response module is used for executing an instruction corresponding to the operation event by using the standard virtual machine under the condition that the value description information is met if the operation event of the user is monitored, so as to realize the response to the operation event.
The standard source program received in the embodiment includes value description information, and a data dictionary and a grammar tree corresponding to the standard source program can be generated based on the value description information, so that the value description information is loaded in the data dictionary, and nodes in the grammar tree conform to the constraint of the value description information on the value range of the variable and/or the function parameter. The embodiment converts the grammar tree into the object code, and packages the object code and the data dictionary into the virtual machine byte code so that the standard virtual machine loads the virtual machine byte code. After detecting the operation event of the user, the instruction corresponding to the operation event can be executed under the condition that the constraint of the value description information on the variable and/or the function parameter value range is met, so that the response to the operation event is realized. In this embodiment, the value description information is used to describe the data value range, and the value description information is used to perform data value verification during program compiling and running, so that lengthy data type and control flow statements are not required to be used to control the data value range, and therefore, the complexity of the control statement of the data value range can be reduced, and the event response efficiency is improved.
Further, the process of generating the data dictionary and the syntax tree corresponding to the standard source program by the compiling module based on the value description information includes: generating the data dictionary according to the contents of a variable table, a constant table and a function table in the standard source program; generating an initial grammar tree according to statement contents of a statement table in the standard source program; judging whether the nodes in the initial grammar tree accord with the value description information loaded in the data dictionary or not; if yes, setting the initial grammar tree as the grammar tree corresponding to the standard source program; if not, outputting prompt information of the writing errors of the standard source program.
Further, the process of the compiling module for packaging the object code and the data dictionary to obtain the virtual machine byte code includes: packaging the object codes to obtain an event table, an event index table and a logic data table; packaging other contents except the value description information in the data dictionary to obtain a variable table, a variable configuration table, a function index table and a function configuration table; packaging the value description information in the data dictionary to obtain a variable value description table and/or a function parameter value description table; and generating the virtual machine byte code according to the packing result of the target code and the packing result of the data dictionary.
Further, if the value description information is used for restricting the value range of the variable, the process of executing the instruction corresponding to the operation event by the event response module by using the standard virtual machine under the condition of conforming to the value description information includes: converting the operation event into an event list and a variable context; wherein the event list comprises event variable names and event variable values; inquiring whether the event variable value accords with the value description information according to the event variable name; if yes, inquiring a target instruction corresponding to the event list, and executing the target instruction by using the standard virtual machine according to the variable context.
Further, the method further comprises the following steps:
The first judging module is used for stopping executing the target instruction if the variable value operation or the variable assignment operation is detected; the method is also used for judging whether the value corresponding to the value taking operation or the assignment operation accords with the value description information; if yes, continuing to execute the target instruction; if not, outputting prompt information of instruction execution errors.
Further, the value description information is further used for restricting the value range of the function parameter, and further includes:
the second judging module is used for stopping executing the target instruction if the function calling operation is detected; the real parameter combination of the objective function corresponding to the function calling operation is also used for judging whether the real parameter combination accords with the value description information; if yes, continuing to execute the target instruction; if not, outputting prompt information of instruction execution errors.
Further, the value description information includes range type value description information and/or enumeration type value description information.
Since the embodiments of the system portion and the embodiments of the method portion correspond to each other, the embodiments of the system portion refer to the description of the embodiments of the method portion, which is not repeated herein.
The present application also provides a storage medium having stored thereon a computer program which, when executed, performs the steps provided by the above embodiments. The storage medium may include: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a random access Memory (Random Access Memory, RAM), a magnetic disk, or an optical disk, or other various media capable of storing program codes.
The application also provides an electronic device, which can comprise a memory and a processor, wherein the memory stores a computer program, and the processor can realize the steps provided by the embodiment when calling the computer program in the memory. Of course the electronic device may also include various network interfaces, power supplies, etc.
In the description, each embodiment is described in a progressive manner, and each embodiment is mainly described by the differences from other embodiments, so that the same similar parts among the embodiments are mutually referred. For the system disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant points refer to the description of the method section. It should be noted that it will be apparent to those skilled in the art that various modifications and adaptations of the application can be made without departing from the principles of the application and these modifications and adaptations are intended to be within the scope of the application as defined in the following claims.
It should also be noted that in this specification, relational terms such as first and second, and the like are used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Moreover, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one … …" does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises the element.

Claims (10)

1. An event response method, comprising:
Receiving a standard source program input by a user; the standard source program comprises value description information, wherein the value description information is used for restricting the value range of the variable and/or the function parameter;
Generating a data dictionary and a grammar tree corresponding to the standard source program based on the value description information; wherein, the value description information is loaded in the data dictionary, and nodes in the grammar tree accord with the value description information;
Converting the grammar tree into an object code, and packaging the object code and the data dictionary to obtain a virtual machine byte code so that a standard virtual machine loads the virtual machine byte code; wherein, the virtual machine byte code comprises a data table corresponding to the value description information;
If the operation event of the user is monitored, executing an instruction corresponding to the operation event by using the standard virtual machine under the condition that the value description information is met, so as to respond to the operation event.
2. The event response method according to claim 1, wherein generating the data dictionary and syntax tree corresponding to the standard source program based on the value description information comprises:
generating the data dictionary according to the contents of a variable table, a constant table and a function table in the standard source program;
Generating an initial grammar tree according to statement contents of a statement table in the standard source program;
judging whether the nodes in the initial grammar tree accord with the value description information loaded in the data dictionary or not; if yes, setting the initial grammar tree as the grammar tree corresponding to the standard source program; if not, outputting prompt information of the writing errors of the standard source program.
3. The event response method of claim 1, wherein packaging the object code and the data dictionary to obtain virtual machine bytecodes comprises:
Packaging the object codes to obtain an event table, an event index table and a logic data table;
Packaging other contents except the value description information in the data dictionary to obtain a variable table, a variable configuration table, a function index table and a function configuration table;
Packaging the value description information in the data dictionary to obtain a variable value description table and/or a function parameter value description table;
And generating the virtual machine byte code according to the packing result of the target code and the packing result of the data dictionary.
4. The event response method according to claim 1, wherein if the value description information is used to constrain a value range of a variable, executing, by the standard virtual machine, an instruction corresponding to the operation event if the value description information is met, including:
converting the operation event into an event list and a variable context; wherein the event list comprises event variable names and event variable values;
inquiring whether the event variable value accords with the value description information according to the event variable name;
if yes, inquiring a target instruction corresponding to the event list, and executing the target instruction by using the standard virtual machine according to the variable context.
5. The event response method of claim 4, wherein in executing the target instruction according to the variable context using the standard virtual machine, further comprising:
If the variable value operation or the variable assignment operation is detected, stopping executing the target instruction;
judging whether a value corresponding to a value taking operation or a value assigning operation accords with the value description information or not;
If yes, continuing to execute the target instruction;
if not, outputting prompt information of instruction execution errors.
6. The event response method according to claim 4, wherein the value description information is further used to constrain a range of values of a function parameter, and further comprising, in executing the target instruction according to the variable context using the standard virtual machine:
If the function calling operation is detected, stopping executing the target instruction;
Judging whether the real parameter combination of the objective function corresponding to the function calling operation accords with the value description information or not;
If yes, continuing to execute the target instruction;
if not, outputting prompt information of instruction execution errors.
7. The event response method according to any of claims 1 to 6, wherein the value description information comprises range-type value description information and/or enumeration-type value description information.
8. An event response system, comprising:
the source program receiving module is used for receiving a standard source program input by a user; the standard source program comprises value description information, wherein the value description information is used for restricting the value range of the variable and/or the function parameter;
The compiling module is used for generating a data dictionary and a grammar tree corresponding to the standard source program based on the value description information; wherein, the value description information is loaded in the data dictionary, and nodes in the grammar tree accord with the value description information; the grammar tree is further used for converting the grammar tree into an object code, and packaging the object code and the data dictionary to obtain a virtual machine byte code so that a standard virtual machine loads the virtual machine byte code; wherein, the virtual machine byte code comprises a data table corresponding to the value description information;
And the event response module is used for executing an instruction corresponding to the operation event by using the standard virtual machine under the condition that the value description information is met if the operation event of the user is monitored, so as to realize the response to the operation event.
9. An electronic device comprising a memory and a processor, the memory having stored therein a computer program, the processor implementing the steps of the event response method of any of claims 1 to 7 when the computer program in the memory is invoked by the processor.
10. A storage medium having stored therein computer executable instructions which when loaded and executed by a processor implement the steps of the event response method of any of claims 1 to 7.
CN202410117646.1A 2024-01-26 2024-01-26 Event response method, system, electronic equipment and storage medium Pending CN117992183A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202410117646.1A CN117992183A (en) 2024-01-26 2024-01-26 Event response method, system, electronic equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202410117646.1A CN117992183A (en) 2024-01-26 2024-01-26 Event response method, system, electronic equipment and storage medium

Publications (1)

Publication Number Publication Date
CN117992183A true CN117992183A (en) 2024-05-07

Family

ID=90888706

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202410117646.1A Pending CN117992183A (en) 2024-01-26 2024-01-26 Event response method, system, electronic equipment and storage medium

Country Status (1)

Country Link
CN (1) CN117992183A (en)

Similar Documents

Publication Publication Date Title
Tanenbaum et al. A practical tool kit for making portable compilers
US6738967B1 (en) Compiling for multiple virtual machines targeting different processor architectures
Mulligan et al. Lem: reusable engineering of real-world semantics
Grimm Better extensibility through modular syntax
KR101150003B1 (en) Software development infrastructure
US8332828B2 (en) System for translating diverse programming languages
US7313773B1 (en) Method and device for simulator generation based on semantic to behavioral translation
JP5851396B2 (en) Processing method
JP4057938B2 (en) Compiler, compiling method, and program development tool
US7530061B2 (en) Programmatic access to the widest mode floating-point arithmetic supported by a processor
Guth A formal semantics of Python 3.3
Keep et al. A nanopass framework for commercial compiler development
WO1992015937A1 (en) Automatic flowgraph generation for program analysis and translation
US20050015759A1 (en) Method and system for translating programming languages
JPH06501579A (en) Method and apparatus for expressing effects and dependencies of programming operations
Aho Compilers: Principles, Techniques and Tools (for VTU)
US7441237B2 (en) System and method for extending a compiler through a composer
Pandey et al. LLVM cookbook
Tanaka et al. Safe low-level code generation in Coq using monomorphization and monadification
US20230367569A1 (en) Method of generating a representation of a program logic, decompilation apparatus, recompilation system and computer program products
CN117992183A (en) Event response method, system, electronic equipment and storage medium
WO2021208867A1 (en) Cross-platform code conversion method and device
Eckhardt et al. Implicitly heterogeneous multi-stage programming
Poole Portable and adaptable compilers
Tuong et al. Isabelle/C

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination