CN112114812B - Grammar checking method applied to industrial robot programming language - Google Patents
Grammar checking method applied to industrial robot programming language Download PDFInfo
- Publication number
- CN112114812B CN112114812B CN202010874055.0A CN202010874055A CN112114812B CN 112114812 B CN112114812 B CN 112114812B CN 202010874055 A CN202010874055 A CN 202010874055A CN 112114812 B CN112114812 B CN 112114812B
- Authority
- CN
- China
- Prior art keywords
- instruction
- statement
- line
- control flow
- name
- 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
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/40—Transformation of program code
- G06F8/41—Compilation
- G06F8/42—Syntactic analysis
- G06F8/425—Lexical analysis
Landscapes
- Engineering & Computer Science (AREA)
- General Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Software Systems (AREA)
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- Devices For Executing Special Programs (AREA)
Abstract
The invention discloses a grammar checking method applied to an industrial robot programming language, aiming at a robot language improved by a computer general language, classifying and summarizing instruction grammars into a grammar description document, reading program variable data and program statements, segmenting a program according to a program flow control instruction in an instruction detailed description, calculating nested hierarchy indexes of each line of statements, and finally searching instructions line by line, checking the parameter number and the parameter type of the instructions, checking separators of the instructions and the like; and summarizing the checking results of each line to form a grammar checking result. The robot language grammar is customized, so that the addition, deletion and change of the instructions can be quickly completed; and (5) dividing the program according to the hierarchy index, and quickly checking.
Description
Technical Field
The invention relates to the field of grammar lexical analysis, in particular to a grammar checking method of an industrial robot programming language.
Background
Efficient and accurate lexical grammar analysis is one of keys for realizing translation of an industrial robot language program to executable target codes. From the perspective of various robot languages developed at home and abroad, the development modes of robot grammar are divided into three types: 1) generating a brand new language; 2) modifying a computer general language and adding some syntax or rules; 3) adding new subprograms on the original computer programming language.
The existing grammar checking method mainly has the following defects: 1) the expandability is low: the robot programming instructions are not abstractly summarized into instruction description documents in a unified form, so that the workload is large when the instructions are increased; 2) the inspection efficiency is low: each row of instruction statements is checked sequentially from top to bottom without block checking the program statements.
Disclosure of Invention
The invention aims to provide a grammar checking method applied to an industrial robot programming language.
The technical scheme for realizing the purpose of the invention is as follows: a grammar checking method applied to an industrial robot programming language comprises the following steps:
step1, designing and compiling a grammar detailed description document;
step2, reading robot program content and reading a robot instruction grammar description;
step3, extracting a nested structure and calculating a hierarchy index;
and 4, checking line by line statements according to the syntax description.
Further, the method for designing the grammar specification document comprises the following steps: and filling an instruction name, an instruction type, an instruction parameter type, a dependent instruction and a partner instruction into the XML node tree, wherein the general form of the instruction is as follows:
further, step2 reads the program content and instruction description, specifically:
reading the content of the robot program, including code Sentences Sences [0: n ] and variable information Vars [0: m ] of the robot language; reading the instruction specification CmdInfos [0: k ] in the robot language document; searching the instruction name in each line of statement line by line according to the instruction specification CmdInfos; the instruction name search results of the statements are divided into three types: no instruction, one instruction, multiple instructions;
the robot program comprises a programming statement text and a variable information text in the programming statement; sequences [0: n ] represents an array composed of n rows of programming statements; vars [0: m ] represents m variable information contained in n-row programming, including robot position attitude variables, digital quantity IO control variables, analog quantity IO control variables and the like; CmdInfos [0: k ] represents the k instruction specification arrays contained in the grammar specification document of claim 2.
Further, a recursive algorithm for calculating the hierarchy index comprises the following steps:
step 1: after all sentences in the sentence section are traversed, returning the hierarchical index of the sentence section and ending;
step 2: when the current statement is not the control flow starting statement, the level index of the current line statement is level, the result is stored, the index points to the next line statement, and the Step1 is continued; otherwise, Step3 is executed;
step 3: searching a control flow termination statement; the hierarchical indexes of the control flow starting statement and the control flow terminating statement are both level, a sub-sentence segment SubSenence [ j: k ] between the control flow starting statement and the control flow terminating statement is divided, alg _ content _ level is called recursively, the SubSenence [ j: k ] is used as parameter input, and the initial index of the sub-sentence segment is level + 1;
step 4: according to the storage sequence, the hierarchy index of the control flow starting statement is stored, then the hierarchy index list of statement segments SubSences [ j: k ] is stored, and finally the hierarchy index of the control flow ending statement is stored.
Wherein, the algorithm name is: alg _ presence _ level; inputting: the sentence Sences [0: n ], initial index level; and (3) outputting: a statement hierarchy index list stored in sequence according to the line number; SubSences [ j: k ] represents the sub-sentence segment contained in the current control flow instruction, and j, k represent the start index and the end index of the sub-sentence segment in the programming sentence array respectively.
Compared with the prior art, the invention has the following remarkable advantages:
(1) the robot language grammar is customized, and the addition, deletion and change of the instructions can be completed quickly.
(2) And (5) dividing the program according to the hierarchy index, and quickly checking.
The present invention is described in further detail below with reference to the attached drawing figures.
Drawings
FIG. 1 is a flow chart of syntax checking according to the present invention.
FIG. 2 is a flow chart of the present invention for computing a statement level index.
Detailed Description
Aiming at the robot language of the mode 2) in the background technology, the invention classifies and summarizes instruction grammar into a grammar description document, reads program variable data and program sentences, divides the program according to a program flow control instruction in the instruction detailed description, calculates nested level indexes of each line of sentences, finally searches the instructions line by line, checks the parameter number and the parameter type of the instructions, checks separators of the instructions and the like. And summarizing the checking results of each line to form a grammar checking result.
XML is an abbreviation for extensible Markup Language (Extenetnible Markup Language), and XML documents are used to describe data. The present invention uses XML documents to store instruction specifications for the robot language.
Recursion is a method and idea to analyze and solve problems in the form of functions calling themselves directly or indirectly. When the problem to be solved satisfies the following two conditions, a recursive method can be used to solve the problem: 1) the problem can be decomposed into sub-problems of smaller scale but the same nature as the original problem; 2) with a recursive termination condition.
As shown in fig. 1, the present invention provides a syntax checking method applied to an industrial robot programming language, comprising the following steps:
step 1: instruction specification document for designing robot language
The instructions are classified according to instruction functions such as motion control, control flow, IO signal control, system setting, operation, and the like, and are written in XML in detail. General form of the instructions:
wherein < key > and </key > appear as a set of tags and in pairs, representing that the multi-line text content between two tags is a complete robot programming instruction description; name in < key > tag represents the name of the instruction, type represents the type of the instruction; < param/> describes one parameter of the robot programming instruction as a separately appearing tag, where name in the tag represents the name of the current parameter and type in the tag represents the type of the current parameter; for a wide variety of robot programming instructions, a partial instruction does not contain a parameter and does not have a < param/> tag; part of the instruction contains one or more < param/> tags. The robot programming instruction is innovatively described in a general form, and the instruction name, the instruction type and the instruction parameters are more intuitive.
And filling all instructions in the robot language into the XML file according to the form.
And 2, step: reading programs and instruction descriptions
The text content of the robot program, including the code Sentences Sences [0: n ] and variable information Vars [0: m ] of the robot language, is read. The instruction specification CmdInfos [0: k ] in the robot language document is read. And searching the instruction names in each line of sentences line by line according to the instruction descriptions CmdInfos. The instruction name search results of the statements are divided into three types: no instruction, one instruction, multiple instructions. The instruction names contained in all the sentences constitute the instruction name list Cmds of the robot program.
And step 3: computing a hierarchy index
For a robot programming language, a control flow instruction is a special instruction, and is changed from statements such as if condition statements and loop statements in a general computer language. In order to achieve the purpose of simplification, separators such as curly brackets, "}" and the like in a general computer language are removed, and a control flow instruction is evolved into four components:
1) controlling flow starting sentences and conditional expressions;
2) executing the statement;
3) substructure (optionally, by default);
4) a control flow termination statement.
In order to vividly show the hierarchical structure of the control flow starting instruction, the terminating statement, the executing statement and the sub-statement, the method of adding indentation to the starting position of the statement is adopted for the executing statement and the sub-statement. The present invention defines a hierarchical index to represent nesting relationships between statements.
If the robot program includes a control flow command, a control flow command sentence segment (denoted as sentence segment 1) may be used as a substructure of the robot program, and the sentence segment 1 may also include a new control flow command segment (denoted as sentence segment 2). Because of the progressive inclusion relationship between sentence segment 2 and sentence segment 1, sentence segment 1 and the robot program, a nested structure is formed. And the control flow termination statement or the sentence segment can be used as a recursion termination condition after traversing, so that the problem of calculating the hierarchy index of the robot program can be solved by using a recursion method. With reference to fig. 2, the hierarchical index algorithm for the statements in the computer program is as follows:
the algorithm name is as follows: alg _ presence _ level; inputting: the sentence Sences [0: n ], initial index level; and (3) outputting: and (4) a statement hierarchy index list which is stored in sequence according to the line number.
Step 1: after all sentences in the sentence section are traversed, returning the hierarchical index of the sentence section and ending; (cut-off conditions)
Step 2: when the current statement is not the control flow start statement, the level index of the current line statement is level, the result is stored, the index points to the next line statement, and the Step1 is continued. Otherwise, Step3 is executed;
step 3: find control flow termination statements. The hierarchical indexes of the control flow starting sentence and the control flow ending sentence are both level, a sub-sentence segment (marked as SubSenterces [ j: k ]) between the control flow starting sentence and the control flow ending sentence is divided, alg _ sense _ level is recursively called, the SubSenterces [ j: k ] is used as parameter input, and the initial index of the sub-sentence segment is level + 1;
step 4: according to the storage sequence, the hierarchy index of the control flow starting statement is stored, then the hierarchy index list of statement segments SubSences [ j: k ] is stored, and finally the hierarchy index of the control flow ending statement is stored.
Wherein, subsequences [ j: k ] represents the sub-sentence segment contained in the current control flow instruction, and j and k represent the initial index and the end index of the sub-sentence segment in the programming sentence array respectively.
And 4, step 4: line by line inspection
Each row of statements is checked sequentially in the robot program according to the hierarchical index list and the instruction name list. The examination types include: the number of instructions, the number of instruction parameters, the type of instruction parameters, whether the instructions contain separators, whether the logic expressions are complete, whether the control flow instructions are complete, and the like. And for each line of statement, checking in turn according to the checking type.
Exemplary embodiments of the present invention will be described in detail below with reference to the accompanying drawings. The description of the exemplary embodiments is for purposes of illustration only and is not intended to limit the invention, its application, or uses.
Examples
With reference to fig. 1, a syntax checking method applied to an industrial robot programming language includes the following steps:
step 1: instruction specification document for designing robot language
The linear motion Lin instruction is taken as an example for explanation:
the description of the Lin instruction (6 lines of text starting and ending with a tag key) is taken as a node, and its parent node Type contains the text information "Motion" indicating that all its child node types are Motion (Motion control). The parameters of the Lin instruction are described as follows:
the name of the first parameter is targetPos, which represents a moving target point, and the type of the parameter is POS; the second parameter, named speed, represents the dynamics of the motion: speed, acceleration, deceleration, etc., of type DYN; the names of the three parameters are trans, which represent the transition characteristic of motion, and the type is OVL; the fourth parameter is named mode, which represents the motion mode, and is of type DINT.
And 2, step: reading programs and instruction specifications
And reading the text content of the robot program, including code sentences Codes and variable information Vars of the robot language. The instruction specification CmdInfos in the robot language document is read. And searching the instruction names in each line of sentences line by line according to the instruction descriptions CmdInfos.
And step 3: computing a hierarchy index
For a robot programming language, a control flow instruction is a special instruction, and is changed from statements such as if condition statements and loop statements in a general computer language. The control flow instruction evolves into four components:
1) control flow start statements and conditional expressions (in the same row of statements);
2) executing the statement;
3) substructures (optionally, by default);
4) a control flow termination statement.
The algorithm name is: alg _ presence _ level; inputting: the sentence Sences [0: n ], initial index level; and (3) outputting: and (4) sequentially storing statement level index lists according to the line numbers.
The algorithm for calculating the level indexes of the sentence segments comprises the following steps:
step 1: after all sentences in the sentence section are traversed, returning the hierarchical index of the sentence section and ending; (cut-off Condition)
Step 2: when the current statement is not the control flow start statement, the level index of the current line statement is level, the result is stored, the index points to the next line statement, and the Step1 is continued. Otherwise, Step3 is executed;
step 3: find control flow termination statements. The hierarchical indexes of the control flow starting statement and the control flow terminating statement are both level, a sub-statement segment (marked as subsequences [ j: k ]) between the control flow starting statement and the control flow terminating statement is divided, alg _ content _ level is called recursively, the subsequences [ j: k ] are used as parameters to be input, and the initial index of the sub-statement segment is level + 1;
step 4: according to the storage sequence, the hierarchy index of the control flow starting statement is stored, then the hierarchy index list of statement segments SubSences [ j: k ] is stored, and finally the hierarchy index of the control flow ending statement is stored.
According to the recursive algorithm of the sentence segment hierarchy index, the hierarchy index calculation result obtained for the sentences in table 1 is as follows:
table 1 statement examination description
Line number | Sentence | Hierarchy index | Instruction name | Status of state |
0 | //This is a test program | 0 | Is free of | Note that |
1 | Lin(p1) | 0 | Lin | |
2 | IF 3>2THEN | 0 | IF…THEN | |
3 | └┘Lin(p2) | 1 | Lin | |
4 | ELSIF 3<1THEN | 0 | ELSIF…THEN | |
5 | └┘Lin(p3) | 1 | Lin | |
6 | └┘IF 10THEN | 1 | IF…THEN | |
7 | └┘└┘Lin(p4) | 2 | Lin | |
8 | 2 | Is free of | Blank line | |
9 | └┘END_IF | 1 | END_IF | |
10 | ELSE | 0 | ELSE | |
11 | └┘Lin(p5) | 1 | Lin | |
12 | END_IF | 0 | END_IF |
And 4, step 4: line by line inspection
Each row of statements is checked sequentially in the robot program according to the hierarchical index list and the instruction name list. The examination types include: the number of instructions, the number of instruction parameters, the type of instruction parameters, whether the instructions contain delimiters, whether the logic expressions are complete, whether the control flow instructions are complete, etc.
Claims (3)
1. A grammar checking method applied to an industrial robot programming language is characterized by comprising the following steps:
step1, designing and compiling a grammar detailed description document; the method for designing the grammar specification document comprises the following steps: filling an instruction name, an instruction type, an instruction parameter type, a dependent instruction and a partner instruction into the XML node tree;
step2, reading robot program content and reading a robot instruction grammar description; the method specifically comprises the following steps:
reading the content of the robot program, including code Sentences Sences [0: n ] and variable information Vars [0: m ] of the robot language; reading the instruction specification CmdInfos [0: k ] in the robot language document; searching the instruction names in each line of sentences line by line according to the instruction descriptions CmdInfos; the instruction name search results of the statements are divided into three types: no instruction, one instruction, multiple instructions;
wherein, the sequences [0: n ] represents an array formed by n rows of programming statements; vars [0: m ] represents m variable information contained in the programming of n rows; CmdInfos [0: k ] represents k instruction description arrays contained in the grammar specification document;
step3, extracting a nested structure and calculating a hierarchy index;
recursive algorithm for calculating hierarchy index, algorithm name: alg _ presence _ level; inputting: the statement Sences [0: n ], initial index level; and (3) outputting: a statement hierarchy index list stored in sequence according to the line number; the algorithm comprises the following steps:
step 1: after all sentences in the sentence section are traversed, returning the hierarchical index of the sentence section and ending;
step 2: when the current statement is not the control flow starting statement, the level index of the current line statement is level, the result is stored, the index points to the next line statement, and Step1 is continued; otherwise, Step3 is executed;
step 3: searching a control flow termination statement; the hierarchical indexes of the control flow starting statement and the control flow terminating statement are both level, a sub-sentence segment SubSenence [ j: p ] between the control flow starting statement and the control flow terminating statement is divided, alg _ content _ level is called recursively, the SubSenence [ j: p ] is used as parameter input, and the initial index of the sub-sentence segment is level + 1;
step 4: according to the storage sequence, storing the hierarchical index of the control flow initial sentence, then storing the hierarchical index list of the sentence segment SubSences [ j: p ], and finally storing the hierarchical index of the control flow termination sentence;
and 4, checking line by line statements according to the grammar description.
2. A syntax checking method to be applied in an industrial robot programming language according to claim 1 wherein the instructions are in the general form:
<key name=”name”type=”type”>
<param name=”name1”type=”type1”/>
…
<param name=”nameN”type=”typeN”/>
</key>
wherein < key > and </key > appear as a set of tags and in pairs, representing that the multi-line text content between two tags is a complete robot programming instruction description; name in < key > tag represents the name of the instruction, type represents the type of the instruction; < param/> describes one parameter of the robot programming instruction as a separately appearing tag, the name in the tag represents the name of the current parameter, and the type in the tag represents the type of the current parameter.
3. A syntax checking method to be applied in an industrial robot programming language according to claim 1, characterized in that the checking is performed in lines of sentences according to the syntax description, in particular:
checking each line of statements in the robot program in sequence according to the hierarchy index list and the instruction name list; the examination types include: the number of instructions, the number of instruction parameters, the type of instruction parameters, whether the instructions contain separators, whether the logic expression is complete, and whether the control flow instructions are complete.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202010874055.0A CN112114812B (en) | 2020-08-26 | 2020-08-26 | Grammar checking method applied to industrial robot programming language |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202010874055.0A CN112114812B (en) | 2020-08-26 | 2020-08-26 | Grammar checking method applied to industrial robot programming language |
Publications (2)
Publication Number | Publication Date |
---|---|
CN112114812A CN112114812A (en) | 2020-12-22 |
CN112114812B true CN112114812B (en) | 2022-09-27 |
Family
ID=73804192
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202010874055.0A Active CN112114812B (en) | 2020-08-26 | 2020-08-26 | Grammar checking method applied to industrial robot programming language |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN112114812B (en) |
Families Citing this family (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN113687832B (en) * | 2021-10-27 | 2022-03-04 | 上海捷勃特机器人有限公司 | Robot program storage and compiling method |
Family Cites Families (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
JP5325921B2 (en) * | 2011-03-28 | 2013-10-23 | 株式会社東芝 | Decoder compiler, program and communication equipment |
CN103294666B (en) * | 2013-05-28 | 2017-03-01 | 百度在线网络技术(北京)有限公司 | Grammar compilation method, semantic analytic method and corresponding intrument |
CN110032363B (en) * | 2019-03-21 | 2023-07-07 | 深圳点猫科技有限公司 | Data structure construction method and system for robot programming |
CN111309299A (en) * | 2020-01-15 | 2020-06-19 | 珠海格力智能装备有限公司 | Industrial robot language processing method and device, storage medium and electronic equipment |
-
2020
- 2020-08-26 CN CN202010874055.0A patent/CN112114812B/en active Active
Also Published As
Publication number | Publication date |
---|---|
CN112114812A (en) | 2020-12-22 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US7251777B1 (en) | Method and system for automated structuring of textual documents | |
US7454413B2 (en) | Query expressions and interactions with metadata | |
CN107203468B (en) | AST-based software version evolution comparative analysis method | |
JP5592591B2 (en) | A system for creating relationships between items and navigating items | |
CN111462327B (en) | Unstructured data analysis method for three-dimensional inspection model of three-dimensional modeling software | |
JP2000148461A (en) | Software model and existing source code synchronizing method and device | |
US8539442B2 (en) | Reverse engineering for code file refactorization and conversion | |
CN1834903A (en) | Method and computer-readable medium for fitting text to shapes within a graphic | |
CN110502227A (en) | The method and device of code completion, storage medium, electronic equipment | |
JP2009535730A (en) | Generic interface for deep embedding of expression trees in programming languages | |
US8595215B2 (en) | Apparatus, method, and computer program product for processing query | |
CN113918512A (en) | Power grid operation rule knowledge graph construction system and method | |
US5822592A (en) | Method and system for determining source code location | |
CN108766507B (en) | CQL and standard information model openEHR-based clinical quality index calculation method | |
CN108491381B (en) | Syntax analysis method of Chinese binary structure | |
CN112114812B (en) | Grammar checking method applied to industrial robot programming language | |
Dohrn et al. | Design and implementation of wiki content transformations and refactorings | |
Rajbhoj et al. | DocToModel: automated authoring of models from diverse requirements specification documents | |
CN117196043B (en) | Ontology-based knowledge reasoning method and system and electronic equipment | |
Teufel et al. | C2 compiler concepts | |
CN117608656A (en) | Mixed front end frame migration method based on AST and LLM | |
CN114611714B (en) | Model processing method, device, system, electronic equipment and storage medium | |
CN116306391B (en) | Character string processing system and method for integrated circuit design | |
US20230376310A1 (en) | Information processing method and information processing apparatus | |
CN111381814A (en) | Method and device for generating syntax tree of code file and electronic equipment |
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 | ||
CP01 | Change in the name or title of a patent holder |
Address after: 222001 No.18 Shenghu Road, Lianyungang City, Jiangsu Province Patentee after: The 716th Research Institute of China Shipbuilding Corp. Patentee after: JIANGSU JARI TECHNOLOGY GROUP Co.,Ltd. Address before: 222001 No.18 Shenghu Road, Lianyungang City, Jiangsu Province Patentee before: 716TH RESEARCH INSTITUTE OF CHINA SHIPBUILDING INDUSTRY Corp. Patentee before: JIANGSU JARI TECHNOLOGY GROUP Co.,Ltd. |
|
CP01 | Change in the name or title of a patent holder |