CN113220277B - Development method and device for embedded service - Google Patents

Development method and device for embedded service Download PDF

Info

Publication number
CN113220277B
CN113220277B CN202110611631.7A CN202110611631A CN113220277B CN 113220277 B CN113220277 B CN 113220277B CN 202110611631 A CN202110611631 A CN 202110611631A CN 113220277 B CN113220277 B CN 113220277B
Authority
CN
China
Prior art keywords
esvclisp
embedded
expression
service
reading
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.)
Active
Application number
CN202110611631.7A
Other languages
Chinese (zh)
Other versions
CN113220277A (en
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.)
Northwestern Polytechnical University
Original Assignee
Northwestern Polytechnical University
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 Northwestern Polytechnical University filed Critical Northwestern Polytechnical University
Priority to CN202110611631.7A priority Critical patent/CN113220277B/en
Publication of CN113220277A publication Critical patent/CN113220277A/en
Application granted granted Critical
Publication of CN113220277B publication Critical patent/CN113220277B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/20Software design
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/42Syntactic analysis
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/42Syntactic analysis
    • G06F8/427Parsing
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/43Checking; Contextual analysis

Abstract

The invention discloses a development method and a device for embedded service, and relates to the technical field of embedded development. The method and the device are used for solving the problems of high development cost and low efficiency in the development of the embedded service caused by complex development flow of the embedded service in the prior art. The method comprises the following steps: reading ESvcLisp source codes for realizing embedded services, reading character streams included in the ESvcLisp source codes according to the sequence from left to right, and converting the character streams into tag streams according to word forming rules; identifying various grammar components included in the markup stream according to grammar rules of a source language to obtain a first expression; reducing grammatical sugar contained in the first expression to obtain a second expression; and evaluating the second expression according to an evaluation rule, and outputting an evaluation result so that the embedded device executes the result to realize the embedded service.

Description

Development method and device for embedded service
Technical Field
The invention relates to the technical field of embedded development, in particular to a development method and device for embedded service.
Background
Embedded systems are specialized computer systems that are customized for specific application scenarios and built into the controlled device, with wide application, but severely limited resources. If a number of embedded devices can be interconnected via a network to share system resources as a computing cluster, the computing resources that this cluster can export become significant. For a single embedded device, as long as it can meet the most basic communication requirements, the resources it can utilize will no longer be localized, but the sum of the resources of all the embedded devices with which it is interconnected. This will undoubtedly greatly increase the practicality of the embedded system, effectively overcome its shortcomings while taking advantage of its advantages, thereby being able to take full potential of the embedded device, and being a good thing for the development of the embedded system.
The service is an independent program entity, can respond and return user requests, can be independently deployed, operated and migrated, and has the characteristics of flexibility and light weight. The services are communicated by adopting a lightweight message protocol, and the cooperative work is realized through the communication. The services running on the embedded device are embedded services, and the process of abstracting the functionality of the embedded device as a service is embedded services. The service architecture is realized on the embedded equipment, so that the resources of the embedded equipment can be effectively utilized, and the cooperative work of the embedded equipment is realized. The embedded system is connected from isolation to connection and from resource limitation to cooperation and reciprocity, so that the application scene of the embedded system is greatly widened, the development of the embedded system is promoted, and the reverse feeding of the embedded system to the development progress of human life is finally realized.
In summary, the development flow of the embedded service in the prior art is complex, which results in the problems of high development cost and low efficiency of the development of the embedded service.
Disclosure of Invention
The embodiment of the invention provides a development method and a development device for embedded service, which are used for solving the problems of high development cost and low efficiency in the development of the embedded service caused by complex development flow of the embedded service in the prior art.
The embodiment of the invention provides a development method of embedded service, which comprises the following steps:
reading ESvcLisp source codes for realizing embedded services, reading character streams included in the ESvcLisp source codes according to the sequence from left to right, and converting the character streams into tag streams according to word forming rules;
identifying various grammar components included in the markup stream according to grammar rules of a source language to obtain a first expression; reducing grammatical sugar contained in the first expression to obtain a second expression;
and evaluating the second expression according to an evaluation rule, and outputting an evaluation result so that the embedded device executes the result to realize the embedded service.
Preferably, the character stream of the ESvcLisp source code includes numbers, letters, brackets, spaces, special symbols;
The method for converting the character stream into the mark stream according to the word forming rule specifically comprises the following steps:
and respectively taking the space and the bracket as separators, making segmentation marks on the character stream according to the separators, and converting the character stream into a mark stream according to the segmentation marks.
Preferably, the evaluation rule comprises any one or more of the following combinations:
for a constant atom, the evaluation result is the constant atom itself;
for a symbol, searching a value corresponding to the symbol according to the environment to which the symbol belongs;
for function calls, the individual parameters included in the function are evaluated in the current environment and then the function is called.
Preferably, the evaluating the second expression according to an evaluation rule further includes:
and recycling garbage generated in the evaluation stage by adopting a garbage recycling strategy of mixing a reference count mechanism and a Mark & Sweep mechanism.
Preferably, the reading-in of the ESvcLisp source code ESvcLisp for implementing the embedded service specifically includes:
reading the ESvcLisp source code input by a user in real time from a command line interactive interface; or alternatively
Reading the ESvcLisp source code from the equipment file into a memory to wait for execution as a result; or alternatively
And acquiring the ESvcLisp source code from the network port.
The embodiment of the invention also provides an embedded service development device, which comprises:
the conversion unit is used for reading ESvcLisp source codes for realizing the embedded service, reading character streams included in the ESvcLisp source codes according to the sequence from left to right, and converting the character streams into mark streams according to word formation rules;
an obtaining unit, configured to identify various syntax elements included in the markup stream according to a syntax rule of a source language, and obtain a first expression; reducing grammatical sugar contained in the first expression to obtain a second expression;
and the implementation unit is used for evaluating the second expression according to an evaluation rule and outputting an evaluation result so as to enable the embedded equipment to execute the result and realize the embedded service.
Preferably, the character stream of the ESvcLisp source code includes numbers, letters, brackets, spaces, special symbols;
the method for converting the character stream into the mark stream according to the word forming rule specifically comprises the following steps:
and respectively taking the space and the bracket as separators, making segmentation marks on the character stream according to the separators, and converting the character stream into a mark stream according to the segmentation marks.
Preferably, the evaluation rule comprises any one or more of the following combinations:
for a constant atom, the evaluation result is the constant atom itself;
for a symbol, searching a value corresponding to the symbol according to the environment to which the symbol belongs;
for function calls, the individual parameters included in the function are evaluated in the current environment and then the function is called.
Preferably, the implementation unit is further configured to:
and recycling garbage generated in the evaluation stage by adopting a garbage recycling strategy of mixing a reference count mechanism and a Mark & Sweep mechanism.
Preferably, it is specifically used for:
reading the ESvcLisp source code input by a user in real time from a command line interactive interface; or alternatively
Reading the ESvcLisp source code from the equipment file into a memory to wait for execution as a result; or alternatively
And acquiring the ESvcLisp source code from the network port.
The embodiment of the invention provides a development method and a device for embedded service, wherein the method comprises the following steps: reading ESvcLisp source codes for realizing embedded services, reading character streams included in the ESvcLisp source codes according to the sequence from left to right, and converting the character streams into tag streams according to word forming rules; identifying various grammar components included in the markup stream according to grammar rules of a source language to obtain a first expression; reducing grammatical sugar contained in the first expression to obtain a second expression; and evaluating the second expression according to an evaluation rule, and outputting an evaluation result so that the embedded device executes the result to realize the embedded service. Compared with the existing common language C or C++ for embedded service development, the code provided by the method is concise and has strong expression capability, can help embedded service developers to develop embedded services quickly, and besides, ESvcLisp provides encapsulation for embedded service communication, so that the developers do not need to be annoyed for embedded service communication, and the development efficiency is greatly improved.
Drawings
In order to more clearly illustrate the embodiments of the invention or the technical solutions in the prior art, the drawings that are required in the embodiments or the description of the prior art will be briefly described, it being obvious that the drawings in the following description are only some embodiments of the invention, and that other drawings may be obtained according to these drawings without inventive effort for a person skilled in the art.
FIG. 1 is a schematic flow chart of a development method of embedded service according to an embodiment of the present invention;
fig. 2 is a schematic structural diagram of an embedded server development device according to an embodiment of the present invention.
Detailed Description
The following description of the embodiments of the present invention will be made clearly and completely with reference to the accompanying drawings, in which it is apparent that the embodiments described are only some embodiments of the present invention, but not all embodiments. All other embodiments, which can be made by those skilled in the art based on the embodiments of the invention without making any inventive effort, are intended to be within the scope of the invention.
Fig. 1 is a schematic flow chart of a development method of embedded service according to an embodiment of the present invention.
As shown in fig. 1, the method mainly comprises the following steps:
step 101, reading ESvcLisp source codes for realizing embedded service, reading character streams included in the ESvcLisp source codes according to the sequence from left to right, and converting the character streams into tag streams according to word forming rules;
102, identifying various grammar components included in the markup stream according to grammar rules of a source language to obtain a first expression; reducing grammatical sugar contained in the first expression to obtain a second expression;
and step 103, evaluating the second expression according to an evaluation rule, and outputting an evaluation result so that the embedded device executes the result to realize the embedded service.
Before introducing the development method of embedded service provided by the embodiment of the invention, the service language-ESvcLisp for the embedded system provided by the embodiment of the invention is introduced.
In terms of language design, ESvcLisp contains two parts, an interpreter and a compilation module. Wherein, the interpreter is responsible for the interpretation and execution of the code flow, and the compiling module is responsible for generating auxiliary information. Such as binary messages communicated between embedded services, bytecodes for combinational services, machine codes for computationally intensive modules, and the like.
In terms of application interfaces, ESvcLisp provides a number of support for embedded service development, such as syntax sugars designed for embedded service development at the syntax level, garbage collection at the resource management level, etc.
ESvcLisp language design
The general idea of ESvcLisp language design is that for a general business process, ESvcLisp provides a flexible dynamic language for description, and can develop the business process rapidly. For critical parts with strict requirements on performance and severely limited resources, a compiling module can be adopted to compile the critical parts into a special format capable of accelerating the running speed. In terms of data structure, ESvcLisp contains two basic data structures: tables and atoms, which constitute the programs and data of ESvcLisp.
1.1ESvcLisp interpreter
The ESvcLisp interpreter section is responsible for interpreting the execution of the ESvcLisp code. ESvcLisp is a LISP dialect that inherits many of the features of LISP and adds innovations regarding servicing. ESvcLisp is a gate-function programming language, consisting of expressions, and the process of computation is accomplished by expression evaluation. From a specific form, the program expression of ESvcLisp is a prefix expression. For example, four arithmetic expressions in mathematics, such as: 1+2
In ESvcLisp can be written: (+ 1 2)
Wherein the atoms in ESvcLisp contain both symbolic and numeric atoms.
Specifically, the symbol atom refers to a character string composed of a limited number of letters, special characters and numerals; unlike classical LISP, all atoms in ESvcLisp that cannot be interpreted as number atoms are considered sign atoms, in practice some sign atoms have special meaning, e.g. nil sign atoms represent null types and # t and # f sign atoms represent logical true and logical false, respectively.
The number atoms refer to a series of numbers, the sign of which indicates the positive or negative. For example, 100,1.2,1.2e10, -2,0x1fff,0b10001000, etc. are all atoms.
Further, for atoms 1mnzw and 1234567.S, they contain numbers but cannot be interpreted as numbers, because they contain letters inside, they are both symbol atoms.
Further, the outside and inside may contain not only atoms but also another table. For example, in the expression (+ 1 2) (+ 3 4)), (+ 1 2) is a table, and, (+ 3 4) is also a table, the expression itself being a nested table. The size of the table is not limited in ESvcLisp, and the smallest table is an empty table ().
The table is a very important constituent element in ESvcLisp, and common to the operation of the table are a header, a merge table, an access to an element in the table, and the like. These operations can be accomplished by functions of the operation table built in ESvcLisp, which are fully optimized to fit the underlying platform, functions and examples are shown in table 1.
Table 1 table operations in ESvcLisp
The basic operations provided in table 1 may be combined into more complex operations, implementing various operations on the table. Such as: expression (car (cdr (1 2 3))) whose output is 2, the second element of the fetch list is implemented.
In the case of embedded service development, this work itself is writing a program, and the purpose of writing the program is to process the data. Program and data are two major elements in programming, and in ESvcLisp, both are represented by tables, with homology. If the embedded service developer writes a table in the ESvcLisp source code, the ESvcLisp interpreter will evaluate this table. For example, write an expression in ESvcLisp: after + 1 2), the ESvcLisp interpreter will evaluate it, returning a value of 3; but for the expression: (1 2 3) if the above expression is entered in the ESvcLisp interpreter, an error is obtained: error:1is invalid as a function it means that 1is not a useful function.
In all tables, the first atom is always a function, representing an operation, instruction, command. While the latter atoms or tables are parameters, meaning descriptions of the operation. Namely the expression: (+ 1 2) represents 1+2, and expression: (-4 3) represents 4-3.
ESvcLisp will evaluate all tables, but if one wants to use the table itself as data, it can be prevented from evaluating with only one simple operator, i.e., (single quote) operator.
1.2 syntax of classical LISP inherited by ESvcLisp
The syntax of ESvcLisp inherits the classical LISP in which there are two basic components, namely a variable and a value, which can exist independently of the variable, i.e. without binding the value of the variable, such as a one-time function generated by a lambda expression; the variable may also exist independent of the value, which is a special element, symbol, the Symbol to which the value is bound, i.e. the variable, which is added to the environment.
For example, the expression: environmental: = [ { symbol: value ], which represents the environment, i.e., the set of symbol-value pairs. Each such set of symbol-value pairs constitutes a variable.
TABLE 2 syntax of classical LISP inherited by ESvcLisp
ESvcLisp provides a series of basic operators, divided into mathematical operators, logical operators, etc., for performing mathematical operations and logical operations, respectively, as in table 3.
Table 3 operators in ESvcList
1.3 New syntax introduced by ESvcLisp
TABLE 4ESvcLisp introduced New syntax
ESvcLisp is introduced into a switch expression to match various conditions, so that the unclassified nested if expression is avoided, and the embedded service developer who is familiar with the C language can conveniently and quickly get on hand. Unlike the C language, the switch expression will continue to match backwards only if a certain value does not match. Otherwise, as soon as a matching value is found, the switch expression returns the expression corresponding to the branch. That is, switches in ESvcLisp imply break.
For historical reasons, popularity of the C-series language affects the writing habits of human programming languages, and prefix expressions used by LISP languages are inconsistent with the habits of the masses. For function calls, people are more familiar with writing foo (bar) than writing (foo bar).
For this reason, ESvcLisp extends the concept of representing decorated symbols in LISP like' such placed before brackets, introduces the concept of prefix atoms, and is compatible with the writing method similar to function call in C-series language, so as to reduce migration cost of developers. Thus foo (bar) is also a legal ESvcLisp code. Wherein foo is identified as a prefix atom in the lexical analysis stage, and syntax sugar is removed according to the corresponding rule in the syntax analysis stage, and the syntax sugar becomes (foo bar).
Another purpose of introducing prefix atoms is to simplify ESvcLisp expressions. These prefix atoms tend to be very short, being composed of special characters, representing special meanings. The existence of the ESvcLisp can simplify complex expressions, so that codes of the ESvcLisp are clearer and simpler, and development efficiency is improved.
E.g., ESvcLisp provides several classical prefix tokens in a compatible LISP,' as a prefix token, read as "quote" in LISP, the table element representing the prefix token modification is not a function call but a static list, a collection of elements. For example, the expression: '1 2 3 4, the prefix symbol' of the modifier list 1 2 3 4 is recognized in the lexical analysis stage, expanded into a prefix 1 2 3 4 in the syntax analysis stage, and returned to a table atom containing four number atoms.
In order to facilitate embedded service development, ESvcLisp provides a series of new prefix atoms, which are usually composed of special symbols, are short and easy, can better express the intention of a service developer, and improve the development efficiency. The partial prefix atoms are as in table 5.
Table 5 prefix atom table in ESvcLisp
Among them, classical prefix atoms such as',and @, etc. are also supported among ESvcLisp.
1.4ESvcLisp compiling Module
The ESvcLisp compilation module appears formally as a built-in function, starting the compilation module by function calls. These modules may be written by a developer and process incoming ESvcLisp values.
The ESvcLisp compilation module functions in two situations: first, it is often necessary to generate specific message formats, whether JSON, XML or special binary messages, for network communications. The ESvcLisp compiling module enables ESvcLisp data to be compiled into data in different formats for network transmission, different targets are adapted, the process is hidden for a developer, and mental burden of the developer is reduced.
The ESvcLisp compilation module can accelerate performance bottlenecks, and ESvcLisp, as an interpreted language, tends to be inferior to a compiled language that is compiled directly into the target platform machine code. In order to fully utilize the computing power of the embedded device, the method is suitable for the practical limitation of the resources of the embedded device. For repeatedly executed key codes, the compiling module of the ESvcLisp can start just-in-time compiling to generate machine codes corresponding to the target platform, so that the execution speed is increased. The compiling module of the ESvcLisp can also directly import fully optimized machine codes to solve the performance bottleneck or utilize the existing libraries of other languages.
2. Application interface
The support of embedded servitization by ESvcLisp for developers is embodied in several aspects:
ESvcLisp provides a function-like service interface for developers. The call of the service is used as a remote procedure call, is close to the function call in grammar, and reduces the mental burden of programmers.
ESvcLisp provides macro and grammar sugars that can facilitate expanding the grammar of ESvcLisp, suitable for simplifying service implementation. Meanwhile, the kernel of the ESvcLisp language is kept simple and easy to realize, and the embedded service resource-limited practical application can be conveniently realized in a cross-platform mode.
ESvcLisp provides a garbage collection mechanism, can effectively manage memory resources, and is suitable for practical limitation of embedded system resources.
ESvcLisp provides pattern matching process call data so that embedded service developers do not have to be bothered with cumbersome data format processing.
2.1 function-like service interface
In ESvcLisp, the service is semantically close to a function, and no side effects are generated for the invocation of the service. The declaration of a service is similar to the declaration of a function, the definition of a service is similar to the definition of a service, and the invocation of a service is similar to the invocation of a function. The relationship and differences are shown in Table 6.
TABLE 6 comparison of ESvcLisp functions with services
It should be noted that, here, the prefix atom% # written before the service call table may be omitted, and its main purpose is to emphasize that the call is a service call. If not written, the ESvcLisp interpreter will call itself to the variable bound to the symbol ser, which is a function call if the value of the variable is a function. If the value of the variable binds a service, the call is a service call.
2.2 macro and grammar sugar
ESvcLisp inherits the powerful grammar expansion function of LISP language, and besides built-in grammar sugar convenient to develop, ESvcLisp provides a macro mechanism to enable developers to customize grammar sugar belonging to the developers, so that the ESvcLisp has great significance for service development.
ESvcList may be defined by a defmacro expression, such as (defmacro macro-name macro-body), where macro-body is a lambda expression, but unlike the usual function definition, the mechanism of the lambda expression corresponding to a macro is to be expanded rather than called, i.e. the macro does not evaluate the real parameters passed to it, but is directly replaced. The replaced expression will be expanded further until fully expanded into a basic form. The macro-expanded expression is then evaluated in situ.
For ease of development, ESvcLisp provides a series of grammatical sugars that are expanded after a parse phase and before an evaluate phase, and then the expanded expression is evaluated.
If a function body is defined as a conventional function, only a single expression can be defined, and if multiple expressions are included in the function body, the begin expression must be used for packaging. However, the large occurrence of begin expressions is actually a redundancy of information. The presence of grammatical sugar may enable a developer to omit begin when writing a function definition and then automatically supplement a programmer during the development phase.
Thus, the simplification of the program kernel is ensured, and the program can be operated on an embedded platform with limited resources. Meanwhile, the grammar is ensured to be simple and convenient, so that embedded service developers can develop conveniently.
2.3 garbage recovery and resource management
As is well known, the resources of the embedded device are often severely limited, and the memory resources are used as precious system resources, so that effective management is needed, and memory leakage is avoided.
However, the memory management is too complicated and is prone to error, and the burden on the developer is too heavy, which is not beneficial to the development of embedded services. For this reason ESvcLisp introduces a garbage collection mechanism. The use condition of the memory can be monitored with lower cost, and useless memory is released at a proper time, so that precious memory resources are saved, and the practical limit of embedded service resources is met.
2.4 Pattern matching
Pattern matching is a common function of modern programming languages. Pattern matching provides a convenient way of deconstructing the data structure, and the deconstructing based on pattern matching is often similar in form to the construction of algebraic data types, has consistency, and can greatly reduce mental burden of developers.
The following is an example to illustrate the effect of pattern matching, for the expression
(match'(1 2 3)
[(list a b c)a])
Then after pattern matching is completed, a has a value of 1, b has a value of 2, and c has a value of 3. This process is consistent with the construction of lists in ESvcList, e.g
(define a 1)
(define b 2)
(define c 3)
(list a b c)
The list (1, 2, 3) is returned after evaluation, the construction process is symmetrical to the pattern matching process, and the consistency of the two forms is beneficial to reducing the complexity of language and facilitating the study of developers.
The introduction of pattern matching functionality facilitates the use of ESvcLisp to write embedded services to process received call data. Generally, for network transmission, call data received by an embedded service has a certain structure and a specific format, and the format and structure often differ from the data structure of the embedded service itself, that is, the call data needs to be processed by parsing and converting a native data form of the embedded service. Through the mode matching mechanism of ESvcLisp, the parsing process is hidden for the developer, the developer can describe the data structure straightforwardly, the variables of the computing module are directly bound to the received request data, and the parsing and converting processes are automatically completed, so that the program is concise and clear, and the development efficiency is improved.
The effect of ESvcLisp pattern matching on embedded service development is described below as a simple example. Assuming that the service xorstervice receives a piece of call information encapsulated in a special data format, two boolean values are contained in the call information, the main task of xorstervice is to parse the call information, convert the boolean values into special sign atoms #t and #f representing the boolean values, then perform an exclusive-or operation on the boolean variables, and return the result. Assuming that the received call information is recorded as variable recv-data and the return value is recorded as return-data, there is
Res is a calculation result, and is matched with the concise message data construction grammar of ESvcLisp, so that the calculation process of the service can be easily described, and the method has strong expressive force.
In step 101, the ESvcLisp source code is read in, the character stream included in the ESvcLisp source code is read in sequence from left to right, and the character stream is converted into a tag stream according to a word forming rule.
The reading of ESvcLisp source code includes the following three modes:
first, ESvcLisp source codes input by a user in real time are read in from a command line interactive interface, and a reading-evaluating-outputting cycle is carried out.
Second, the ESvcLisp source code is read into the memory from the device file as a string interpretation execution.
Thirdly, the ESvcLisp interpreter itself is used as an embedded service, monitors a specific port, processes a specific message, and acquires ESvcLisp source codes from a network port, thereby realizing service remote deployment and service migration.
In practical applications, lexical analysis is a process in computer science that converts character sequences into tag sequences. The task at this stage is to read in the ESvcLisp source code character by character from left to right, i.e. scan the character stream comprised by the ESvcLisp source code and then identify the tag according to the word forming rules.
In an embodiment of the present invention, the character stream of the ESvcLisp source code may include numbers, letters, brackets, spaces, special symbols, and the like. Further, in the character stream, spaces and brackets may be used as separators, that is, a character stream may be cut according to the separators, and the character stream may be converted into a mark stream according to the cut.
In practice, ESvcLisp supports three brackets, namely curly brackets { }, square brackets [ ] and parentheses (). These three brackets are semantically equivalent and can be mixed in the code, but care must be taken that brackets are used to match, i.e., left brackets { can only be matched with right brackets }, correspondingly left brackets [ can only be matched with right brackets ], left brackets (can only be matched with right brackets); otherwise, an error is reported.
It should be noted that, in the ESvcLisp lexical analysis stage, each tag is classified according to the word-forming rule. For a label that can be interpreted as a number, its class is a number, corresponding to the number atom in ESvcLisp. In particular, if a token ends with left brackets, the token may be a prefix atom. If the token cannot be interpreted as a number, but is instead interpreted as a symbol, the category of the token is a prefix token, corresponding to the prefix atom in ESvcLisp: the identification of prefix atoms is done in the lexical analysis stage.
In step 102, identifying various grammar components included in the markup stream according to grammar rules of a source language to obtain a first expression; reducing grammatical sugar contained in the first expression to obtain a second expression;
in the embodiment of the invention, the grammar analysis is to identify various grammar components from the mark sequence output by the lexical analysis stage according to the grammar rules of the source language. The stage of parsing ESvcLisp is similar to that of classical LISP, and will not be described here again.
It should be noted that the prefix atom introduced by ESvcLisp affects the behavior of ESvcLisp in the parsing stage. For example, some embedded services require invoking system commands or other native programs of the embedded platform. To simplify this process, the ESvcLisp provides a special prefix atom $ modifier to a table to effect formally mimicking a shell command, allowing a developer to interact with the system as conveniently as writing shell scripts.
Such as: under the Linux platform, all files under a certain folder dir are wanted to be checked, and the following commands can be directly input into the shell:
ls-l/usr/dir
whereas in other languages, such as the C language, writing is required:
system("ls-l/usr/dir");
executing the commands in this manner requires the developer to convert the commands into character strings by various methods to be executed, which increases development costs intangibly. In some cases, this process is very cumbersome. Such as: if "/usr/dir" is stored in the variable mydir, the developer has to expand mydir to "/usr/dir" before it can be directly imported. In contrast, direct writing is possible in ESvcLisp
%$(ls-l mydir)
mydir stores a string quantity "/usr/dir" as a common variable in the ESvcLisp environment. After being identified by the lexical analysis module and the grammatical analysis module, the%is taken as a prefix expression, for each atom in the table, if a corresponding variable can be found in the current environment, the atom can be replaced by a value corresponding to the variable, otherwise, the atom can be converted into a character string, and the literal value of the symbol atom is the converted character string constant. For atoms of non-string type, such as a number atom, the number atom will be converted into its string representation, and finally the space separated converted atoms will be spliced into a string to generate ESvcList for system call expression
(system“1s-1/usr/dir”)
Further, after identifying each syntax element included in the markup stream according to the syntax rules, a first expression may be obtained, where the first expression may be a complete sentence, or may be a sentence in which some syntax elements are omitted. If the first expression is a complete sentence, evaluating and outputting operations can be performed on the complete sentence; if the first expression is an incomplete sentence, grammar sugar reduction is needed to be carried out on the incomplete sentence to obtain a second expression, and then a complete sentence is obtained.
In the embodiment of the invention, the syntax sugar reduction is a first expression unfolding stage, for example, a function containing a plurality of expressions is packed into a begin expression, and a function definition without lambda expression is reduced into a function definition with lambda expression. The main purpose of this stage is to reduce the expression to a basic form.
This stage also processes the macro definition, which uses defmacro expression definition, similar to the process of function definition, where both the parameters and the macro body of the macro are packed and recorded. The main difference between the macro-unfolding process and the function-calling process is that two points are:
First, macro-stretching does not evaluate the parameters, but brings in post-stretching.
Second, the scope of the function is static. The scope of a macro is dynamic.
The result of the macro expansion is an expression that is evaluated at the macro expansion location after expansion to the base form, thereby acting as an expansion grammar.
This stage also checks the syntax of the code and if a non-syntactical expression is encountered, the expression is refused to execute while a syntax error is reported.
In step 103, the second expression is evaluated according to an evaluation rule. Specifically, the ESvcLisp evaluation phase evaluates the expression, with the evaluation rules generally as follows: for constant atoms, return directly to itself; for a symbol, searching a value corresponding to the symbol according to the current environment and returning; for function call, evaluating each parameter in the current environment, and then performing function call; the process of function call creates a new environment that constructs symbol value pairs with function-shape parameters as symbols and real parameters as values. The process of function evaluation evaluates a function body within this constructed function call environment.
After the evaluation of the second expression is completed, an evaluation result may be output. The result delivery phase refers to the process of displaying the result after evaluation, or the side effect (such as IO) of the expression evaluation.
It should be noted that garbage collection is also performed in the function evaluation stage. In particular, since the main role of ESvcLisp is to develop embedded services, which have some idle time waiting for a network request as a service itself, and the waiting for a network request results from evaluating the network request expression, garbage collection can be performed at this point without dragging the service response. Moreover, the evaluation phase involves the failure of the old value and the generation of the new value, and the memory resource is changed, so that the phase is suitable for starting the garbage collection process.
ESvcLisp employs a garbage collection strategy that combines both reference counting and Mark & Sweep mechanisms. Each ESvcLisp value is at the beginning of the new creation and its reference count is set to 1. When this Lisp value is referenced by another Lisp value, such as when an atom or table becomes a constituent element of another table, the reference count is incremented by 1. Whenever a new value is created, memory resource usage increases and the change is recorded. When a value is released, memory resources are reduced, and the process is tracked. Thus, the ESvcLisp environment is able to sense the change in memory resources in time. When the available memory resources are reduced to the lower limit of the preset threshold value, the garbage collection process is automatically started, the reference counts of all recorded values are reduced by one, and the memory resources occupied by the value of which the reference count is changed to 0 are released. I.e. a value that is only referenced by the ESvcLisp environment itself.
In particular, for a value containing a sub-value, such as a normal ESvcLisp table, when it is reclaimed, its reference count for the sub-value is also decremented by 1, and then it is checked whether the reference count for the sub-value is 0, and if it is 0, the sub-value is also reclaimed.
For the case of self-inclusion, ESvcLisp employs another mechanism to solve the problem of loop referencing. After the first round of garbage collection is completed, the self-contained or circularly referenced value itself is not recovered, and becomes a net-missing fish under the mechanism. At this point, the garbage collection mechanism will begin a second round of garbage collection, which will attempt to decrement the reference count for all values by one, at which time only the value still referenced by ESvcLisp has its reference count not 0.
It should be noted that reference count of 0 at this time does not represent that the value is inaccessible, meaning that the value can be reclaimed. As some of the values that can be referenced by ESvcLisp can still be accessed. At this time, ESvcLisp will temporarily mark these reference count 0 values as reclaimed. Subsequently, ESvcLisp will traverse those values whose reference count is still greater than 0, access their child values, and cancel the tag if their child values are marked for reclamation. Thus, values that are ultimately marked as reclaimed are values that cannot be accessed by other values that do not require reclamation, and are reclaimed.
It is worth mentioning that for some system critical values, such as #t, #f as sign atoms, they are dynamically created at the initialization of the interpreter, but should not be reclaimed at any time. For these values, their reference count is locked to a negative number, as are the reference counts of the sub-values referenced by them. For values where the reference technique is negative, no reclamation is skipped altogether.
Based on the same inventive concept, the embodiment of the invention provides an embedded service development device, and because the principle of solving the technical problem of the device is similar to that of an embedded service development method, the implementation of the device can refer to the implementation of the method, and the repetition is omitted.
Fig. 2 is a schematic structural diagram of an embedded service development device according to an embodiment of the present invention, where, as shown in fig. 2, the device mainly includes: conversion unit 201, obtaining unit 202 and implementation unit 203.
A conversion unit 201, configured to read in an ESvcLisp source code for implementing an embedded service, read a character stream included in the ESvcLisp source code in a sequence from left to right, and convert the character stream into a tag stream according to a word formation rule;
An obtaining unit 202, configured to identify various syntax elements included in the markup stream according to a syntax rule of a source language, so as to obtain a first expression; reducing grammatical sugar contained in the first expression to obtain a second expression;
and the implementation unit 203 is configured to evaluate the second expression according to an evaluation rule, and output an evaluation result, so that the embedded device executes the result to implement the embedded service.
Preferably, the character stream of the ESvcLisp source code includes numbers, letters, brackets, spaces, special symbols;
the method for converting the character stream into the mark stream according to the word forming rule specifically comprises the following steps:
and respectively taking the space and the bracket as separators, making segmentation marks on the character stream according to the separators, and converting the character stream into a mark stream according to the segmentation marks.
Preferably, the evaluation rule comprises any one or more of the following combinations:
for a constant atom, the evaluation result is the constant atom itself;
for a symbol, searching a value corresponding to the symbol according to the environment to which the symbol belongs;
for function calls, the individual parameters included in the function are evaluated in the current environment and then the function is called.
Preferably, the implementation unit 203 is further configured to:
and recycling garbage generated in the evaluation stage by adopting a garbage recycling strategy of mixing a reference count mechanism and a Mark & Sweep mechanism.
Preferably, the conversion unit 201 is specifically configured to:
reading the ESvcLisp source code input by a user in real time from a command line interactive interface; or alternatively
Reading the ESvcLisp source code from the equipment file into a memory to wait for execution as a result; or alternatively
And acquiring the ESvcLisp source code from the network port.
It should be understood that the above development device for embedded service includes units that are only logically divided according to functions implemented by the device, and in practical applications, the above units may be stacked or split. The functions implemented by the embedded service development device provided by this embodiment correspond to the embedded service development method provided by the above embodiment, and the more detailed process flow implemented by the device is described in detail in the above method embodiment one, which is not described in detail herein.
It will be appreciated by those skilled in the art that embodiments of the present invention may be provided as a method, system, or computer program product. Accordingly, the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present invention may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
The present invention is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems) and computer program products according to embodiments of the invention. It will be understood that each flow and/or block of the flowchart illustrations and/or block diagrams, and combinations of flows and/or blocks in the flowchart illustrations and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
While preferred embodiments of the present invention have been described, additional variations and modifications in those embodiments may occur to those skilled in the art once they learn of the basic inventive concepts. It is therefore intended that the following claims be interpreted as including the preferred embodiments and all such alterations and modifications as fall within the scope of the invention.
It will be apparent to those skilled in the art that various modifications and variations can be made to the present invention without departing from the spirit or scope of the invention. Thus, it is intended that the present invention also include such modifications and alterations insofar as they come within the scope of the appended claims or the equivalents thereof.

Claims (8)

1. A method of developing embedded servings, comprising:
Reading ESvcLisp source codes for realizing embedded services, reading character streams included in the ESvcLisp source codes according to the sequence from left to right, and converting the character streams into mark streams according to word forming rules, wherein the ESvcLisp is a service language facing an embedded system;
identifying various grammar components included in the markup stream according to grammar rules of a source language to obtain a first expression; reducing grammatical sugar contained in the first expression to obtain a second expression;
evaluating the second expression according to an evaluation rule, and outputting an evaluation result so that the embedded equipment executes the result to realize embedded service;
the evaluation rule includes any one or more of the following combinations:
for a constant atom, the evaluation result is the constant atom itself;
for a symbol, searching a value corresponding to the symbol according to the environment to which the symbol belongs;
for function calls, the individual parameters included in the function are evaluated in the current environment and then the function is called.
2. The method of claim 1, wherein the character stream of ESvcLisp source code comprises numbers, letters, brackets, spaces, special symbols;
The method for converting the character stream into the mark stream according to the word forming rule specifically comprises the following steps:
and respectively taking the space and the bracket as separators, making segmentation marks on the character stream according to the separators, and converting the character stream into a mark stream according to the segmentation marks.
3. The method of claim 1, wherein the evaluating the second expression according to an evaluation rule further comprises:
and recycling garbage generated in the evaluation stage by adopting a garbage recycling strategy of mixing a reference count mechanism and a Mark & Sweep mechanism.
4. The method according to claim 1, wherein said reading in ESvcLisp source code ESvcLisp for implementing embedded services, in particular comprises:
reading the ESvcLisp source code input by a user in real time from a command line interactive interface; or alternatively
Reading the ESvcLisp source code from the equipment file into a memory to wait for execution as a result; or alternatively
And acquiring the ESvcLisp source code from the network port.
5. An embedded service development device, comprising:
the system comprises a conversion unit, a word forming unit and a word forming unit, wherein the conversion unit is used for reading ESvcLisp source codes for realizing embedded services, reading character streams included in the ESvcLisp source codes according to the sequence from left to right, and converting the character streams into mark streams according to word forming rules, wherein the ESvcLisp is a service language facing an embedded system;
An obtaining unit, configured to identify various syntax elements included in the markup stream according to a syntax rule of a source language, and obtain a first expression; reducing grammatical sugar contained in the first expression to obtain a second expression;
the implementation unit is used for evaluating the second expression according to an evaluation rule and outputting an evaluation result so that the embedded equipment executes the result to realize the embedded service;
the evaluation rule includes any one or more of the following combinations:
for a constant atom, the evaluation result is the constant atom itself;
for a symbol, searching a value corresponding to the symbol according to the environment to which the symbol belongs;
for function calls, the individual parameters included in the function are evaluated in the current environment and then the function is called.
6. The apparatus of claim 5, wherein the character stream of ESvcLisp source code comprises numbers, letters, brackets, spaces, special symbols;
the method for converting the character stream into the mark stream according to the word forming rule specifically comprises the following steps:
and respectively taking the space and the bracket as separators, making segmentation marks on the character stream according to the separators, and converting the character stream into a mark stream according to the segmentation marks.
7. The apparatus of claim 5, wherein the means for implementing is further for:
and recycling garbage generated in the evaluation stage by adopting a garbage recycling strategy of mixing a reference count mechanism and a Mark & Sweep mechanism.
8. The apparatus of claim 5, wherein the conversion unit is specifically configured to:
reading the ESvcLisp source code input by a user in real time from a command line interactive interface; or alternatively
Reading the ESvcLisp source code from the equipment file into a memory to wait for execution as a result; or alternatively
And acquiring the ESvcLisp source code from the network port.
CN202110611631.7A 2021-06-01 2021-06-01 Development method and device for embedded service Active CN113220277B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110611631.7A CN113220277B (en) 2021-06-01 2021-06-01 Development method and device for embedded service

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110611631.7A CN113220277B (en) 2021-06-01 2021-06-01 Development method and device for embedded service

Publications (2)

Publication Number Publication Date
CN113220277A CN113220277A (en) 2021-08-06
CN113220277B true CN113220277B (en) 2023-12-19

Family

ID=77082720

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110611631.7A Active CN113220277B (en) 2021-06-01 2021-06-01 Development method and device for embedded service

Country Status (1)

Country Link
CN (1) CN113220277B (en)

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US4931928A (en) * 1988-11-09 1990-06-05 Greenfeld Norton R Apparatus for analyzing source code
US6473896B1 (en) * 1998-10-13 2002-10-29 Parasoft, Corp. Method and system for graphically generating user-defined rules for checking language quality
WO2007051531A2 (en) * 2005-11-02 2007-05-10 Georg-August-Universität Göttingen - Stiftung Öffentlichen Rechts Method and device for call oriented programming
CN110007926A (en) * 2019-04-17 2019-07-12 广东三维家信息科技有限公司 Language transfer method and device
CN112632924A (en) * 2020-12-18 2021-04-09 上海明略人工智能(集团)有限公司 Method, system, electronic device and storage medium for labeling regularized execution sequence
CN112748914A (en) * 2020-03-18 2021-05-04 腾讯科技(深圳)有限公司 Application program development method and device, electronic equipment and storage medium

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2001098942A2 (en) * 2000-06-19 2001-12-27 Lernout & Hauspie Speech Products N.V. Package driven parsing using structure function grammar
US8813047B2 (en) * 2005-09-08 2014-08-19 Alcatel Lucent Yet another transformation language (YATL)
US9678724B2 (en) * 2015-05-29 2017-06-13 Intentional Software Corporation System and method for combining text editing and tree encoding for computer programs
US10303448B2 (en) * 2016-05-15 2019-05-28 Synopsys, Inc. Systems and methods for graph-based analysis of software

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US4931928A (en) * 1988-11-09 1990-06-05 Greenfeld Norton R Apparatus for analyzing source code
US6473896B1 (en) * 1998-10-13 2002-10-29 Parasoft, Corp. Method and system for graphically generating user-defined rules for checking language quality
WO2007051531A2 (en) * 2005-11-02 2007-05-10 Georg-August-Universität Göttingen - Stiftung Öffentlichen Rechts Method and device for call oriented programming
CN110007926A (en) * 2019-04-17 2019-07-12 广东三维家信息科技有限公司 Language transfer method and device
CN112748914A (en) * 2020-03-18 2021-05-04 腾讯科技(深圳)有限公司 Application program development method and device, electronic equipment and storage medium
CN112632924A (en) * 2020-12-18 2021-04-09 上海明略人工智能(集团)有限公司 Method, system, electronic device and storage medium for labeling regularized execution sequence

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
基于C/C++的词法分析器的设计与实现;廖媛媛等;《现代计算机(专业版)》;20130825(第24期);全文 *
建模语言中的文本表面语法分析方法研究;徐玉坤等;《计算机应用研究》;20080315(第03期);全文 *

Also Published As

Publication number Publication date
CN113220277A (en) 2021-08-06

Similar Documents

Publication Publication Date Title
Giacalone et al. Facile: A symmetric integration of concurrent and functional programming
JP3041222B2 (en) Source code creation system and method
US9342492B1 (en) Methods and systems for the provisioning and execution of a mobile software application
US7665073B2 (en) Compile time meta-object protocol systems and methods
Keays et al. Context-oriented programming
US20130104100A1 (en) Scripting Language for Business Applications
CN108628635A (en) Method, apparatus, equipment and the storage medium of the name that gets parms and local variable name
JPH0383153A (en) Message processing system and method
US5991538A (en) System for generating and using programs in an object-oriented environment with a message dispatch architecture
Watson A practical approach to compiler construction
Fredriksson et al. Seamless distributed computing from the geometry of interaction
de Carvalho Junior et al. Contextual abstraction in a type system for component-based high performance computing platforms
CN113220277B (en) Development method and device for embedded service
Auerbach et al. High-level language support for programming distributed systems.
Haller et al. A reduction semantics for direct-style asynchronous observables
WO2001006357A1 (en) Meta-language for c++ business applications
Geller et al. Pattern Matching for an object-oriented and dynamically typed programming language
Díaz Pernil et al. P-lingua: A programming language for membrane computing
JP2002132502A (en) Automatic creating system and method of distributed object with interpretation of language function
Weelden Putting types to good use
Craigen An application of the m-EVES verification system
Wernli Design and implementation of a code generator for the CAL actor language
Feldman Edward W. Czeck
Liu et al. A generate-test-aggregate parallel programming library: systematic parallel programming for MapReduce
Berthomieu Process calculi at work—an account of the LCS project

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
GR01 Patent grant
GR01 Patent grant