CN107133027A - A kind of syntax tree stratification method for expressing - Google Patents

A kind of syntax tree stratification method for expressing Download PDF

Info

Publication number
CN107133027A
CN107133027A CN201710200792.0A CN201710200792A CN107133027A CN 107133027 A CN107133027 A CN 107133027A CN 201710200792 A CN201710200792 A CN 201710200792A CN 107133027 A CN107133027 A CN 107133027A
Authority
CN
China
Prior art keywords
syntax tree
node
tree
xml file
xml
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
CN201710200792.0A
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.)
NR Electric Co Ltd
NR Engineering Co Ltd
Original Assignee
NR Electric Co Ltd
NR Engineering 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 NR Electric Co Ltd, NR Engineering Co Ltd filed Critical NR Electric Co Ltd
Priority to CN201710200792.0A priority Critical patent/CN107133027A/en
Publication of CN107133027A publication Critical patent/CN107133027A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/31Programming languages or programming paradigms
    • G06F8/314Parallel programming languages
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/42Syntactic analysis

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Computing Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Stored Programmes (AREA)
  • Debugging And Monitoring (AREA)

Abstract

The present invention discloses a kind of syntax tree stratification method for expressing, comprises the following steps:Step 1, syntax tree output intent option is obtained, XML file is created;Step 2, based on depth-first traversal syntax tree, one XML file node of each grammer tree node correspondence, the corresponding class name of grammer tree node creates the node structure of XML file according to the father and son of syntax tree, brotherhood as XML node title;Step 3, it is determined that and exporting the information of grammer tree node:The corresponding data attribute of various node types is exported, is output to according to attribute-name, property value in the corresponding nodes of XML, and exports the corresponding source filename of the node, place starting line number, starting row number, termination line number, termination row number;Step 4, the corresponding XML file of storage syntax tree.Such a method can improve debugging and problem diagnosis efficiency, and solve the large-scale syntax tree of flat bed text representation it is not directly perceived enough, can not folding and expanding the problem of.

Description

A kind of syntax tree stratification method for expressing
Technical field
The invention belongs to compiler processes field, and in particular to a kind of grammer tree representation of IEC61131 texts programming language Method.
Background technology
The corresponding compiler development technologies of language such as current C/C++/JAVA are ripe, and above-mentioned language can be based on GCC Realize that the file destination of different processor is formed.In Industry Control, IEC61131 is general standard, defines structuring text This ST, instruction catalogue IL text-type programming language, are the safe subset languages of industrial control field, have corresponding grammer and the syntax fixed Justice.General compiler such as GCC does not support the special language compilation of industry control.61131 texts can be realized based on flex+bison The morphology of this language and syntactic analysis, and syntax tree is formed, semantic analysis and rear end command output module are developed afterwards.Among these Syntax tree is very important data structure, and syntax tree is the memory data structure formed the syntactic analysis phase, when source program generation When code amount is big, syntax tree is also very huge, and the debugging breakpoints acquisition multi-level hierarchy for being directly based upon internal memory is present not intuitively, no Transparent obstacle.Existing syntax tree intermediate representation method, is the content of text to form flat bed, with text editor or Excel is opened and checked, by being retracted come representational level relation, when syntax tree hierarchical relationship depth or many nodes, still in the presence of not It is enough clear, can not folding and expanding the problem of.A kind of method of energy equivalent representation stratificational grammar tree is needed, to improve compiler development During problem diagnosis and analysis efficiency, thus this case produce.
The content of the invention
The purpose of the present invention, is to provide a kind of syntax tree stratification method for expressing, and it can improve debugging and problem diagnosis Efficiency, and solve the large-scale syntax tree of flat bed text representation it is not directly perceived enough, can not folding and expanding the problem of.
In order to reach above-mentioned purpose, solution of the invention is:
A kind of syntax tree stratification method for expressing, comprises the following steps:
Step 1, syntax tree output intent option is obtained, XML file is created;
Step 2, based on depth-first traversal syntax tree, one XML file node of each grammer tree node correspondence, syntax tree The corresponding class name of node creates the node structure of XML file according to the father and son of syntax tree, brotherhood as XML node title;
Step 3, it is determined that and exporting the information of grammer tree node:The corresponding data attribute of various node types is exported, according to Attribute-name, property value are output in the corresponding nodes of XML, and are exported the corresponding source filename of the node, place starting line number, risen Beginning row number, termination line number, termination row number;
Step 4, the corresponding XML file of storage syntax tree.
It is various for structured text ST language, the instruction catalogue IL language of IEC61131-3 standards in above-mentioned steps 1 The corresponding class of design of node of type.
In above-mentioned steps 1, for structured text ST language, the instruction catalogue IL language of IEC61131-3 standards, support with Configuration, resource, task, program organization unit, function, functional block are organization unit, create some XML files.
In above-mentioned steps 3, for type function, output function name, parameter list information;For statement type, language is exported Sentence keyword, expression formula information;For simple types variable declarations, output variable type, variable name;For complex structure body Categorical variable statement, export structure body type, title, each sub- member variable types and name information.
After above-mentioned steps 4, also comprise the following steps:The corresponding XML file of syntax tree is read, and draws the tree-like of syntax tree Structure, when clicking/double-click the node of syntax tree, according to the filename of record and row, column information, directly opens source file, and Highlight the corresponding character zone of display.
After such scheme, the present invention has the advantages that:
The invention provides a kind of method for expressing that the internal storage structure equivalence of syntax tree is converted to XML file, it is easy to many During people's concurrent development, off line is checked and diagnosed.Based on XML file, usable XML checks software, can divide for large-scale syntax tree Layer open and folding.XML file can be read in man-machine software, reconstructs syntax tree, double-clicks syntax tree, can associate opening source file and aobvious Show corresponding content, realize that middle syntax tree and the two-way of source code are reviewed, improve the efficiency of compiler development and test.
Brief description of the drawings
Fig. 1 is that syntax tree stratification represents schematic diagram in the present invention;
The partial data class name of Fig. 2 syntax trees defines example;
Fig. 3 is syntax tree correspondence XML content example in the present invention.
Embodiment
Below with reference to accompanying drawing, technical scheme is described in detail.
As shown in figure 1, the present invention provides a kind of visualization syntax tree stratification table based on IEC61131 CompilerTools Show method, comprise the following steps:
Step 1, syntax tree output intent option is obtained, XML file is created;
First, syntax tree is formed:To form abstract syntax tree, for the structured text ST languages of IEC61131-3 standards Speech, instruction catalogue IL language, are the corresponding class of various types of design of node, the class formation of bottom is as shown in Fig. 2 csymbol is Base class, clist classes are management chained list classes, can derive the concrete kinds such as function parameter, sentence chain, ctoken classes are with attribute The base class of terminal symbol, such as identifier, constant.Morphological analysis is carried out based on flex, lexical unit sequence is formed.It is based on Bison carries out syntactic analysis, forms the syntax tree structure of internal memory.
Secondly, syntax tree output intent option is obtained, some XML files are created according to option:Support is defined with IEC61131-3 The stratification node such as configuration, resource, task, program organization unit, function, functional block export some discrete XML files and Total XML file.Preferably ,-all represents syntax tree exporting a total XML file.- config is represented according to being configured to Unit exports XML file, and it is that unit exports XML file that-resource, which is represented according to resource, and it is single that-task, which is represented according to task, Position output XML file ,-pou represents to export XML file according to program organization unit.- fb represents that each function, functional block are determined Adopted individually output XML file.By the combination of above-mentioned option, large-scale tree structure can be split as multiple XML files.
Step 2, based on depth-first traversal syntax tree, one XML file node of each grammer tree node correspondence, syntax tree The corresponding class name of node creates the node structure of XML file according to the father and son of syntax tree, brotherhood as XML node title. Such as entitled clib of top level root class, then XML first floor node be<clib>.
Step 3, it is determined that and exporting the information of grammer tree node:The corresponding data attribute of various node types is exported, according to Attribute-name, property value are output in the corresponding nodes of XML, and are exported the corresponding source filename of the node, place starting line number, risen The information such as beginning row number, termination line number, termination row number, wherein, for type function, output function name, parameter list information.For Statement type, output statement keyword, expression formula information.For simple types variable declarations, output variable type, variable name Word.For the statement of complex structure body categorical variable, export structure body type, title, each sub- member variable types and title letter Breath.Attribute and child node content such as function block type includes function name, input/output variable, local variable, sentence.
The corresponding XML file of syntax tree is stored, Fig. 3 is the corresponding XML file fragment samples of a syntax tree.
Step 4, the corresponding XML file of storage syntax tree.
After step 1 to step 4 is completed, the corresponding XML file of syntax tree can be read, syntax tree can be read corresponding some XML file is simultaneously shown, using QT model-view mechanism, the tree structure of syntax tree is formed using QListTree, click/ When double-clicking the node of syntax tree, according to the filename of record and row, column information, source file can be directly opened, and highlight display Corresponding character zone.
Summary, a kind of syntax tree stratification method for expressing of the invention.Grammer is traveled through using depth-first traversal algorithm Tree, syntax tree is converted to the XML file of stratification.Grammer root vertex as XML file top mode, with grammer burl The class name of point exports the association attributes of the node as XML node name.The middle syntax tree of internal storage data is output as intuitively Visual XML file, improves debugging and problem diagnosis efficiency, and it is not straight enough to solve the large-scale syntax tree of flat bed text representation See, can not folding and expanding the problem of.
The technological thought of above example only to illustrate the invention, it is impossible to which protection scope of the present invention is limited with this, it is every According to technological thought proposed by the present invention, any change done on the basis of technical scheme each falls within the scope of the present invention Within.

Claims (5)

1. a kind of syntax tree stratification method for expressing, it is characterised in that comprise the following steps:
Step 1, syntax tree output intent option is obtained, XML file is created;
Step 2, based on depth-first traversal syntax tree, one XML file node of each grammer tree node correspondence, grammer tree node Corresponding class name creates the node structure of XML file according to the father and son of syntax tree, brotherhood as XML node title;
Step 3, it is determined that and exporting the information of grammer tree node:The corresponding data attribute of various node types is exported, according to attribute Name, property value are output in the corresponding nodes of XML, and export the corresponding source filename of the node, place starting line number, starting row Number, terminate line number, terminate row number;
Step 4, the corresponding XML file of storage syntax tree.
2. a kind of syntax tree stratification method for expressing as claimed in claim 1, it is characterised in that:In the step 1, for Structured text ST language, the instruction catalogue IL language of IEC61131-3 standards, are the corresponding class of various types of design of node.
3. a kind of syntax tree stratification method for expressing as claimed in claim 1, it is characterised in that:In the step 1, for Structured text ST language, the instruction catalogue IL language of IEC61131-3 standards, support is to configure, resource, task, program organization list Member, function, functional block are organization unit, create some XML files.
4. a kind of syntax tree stratification method for expressing as claimed in claim 1, it is characterised in that:In the step 3, for letter Several classes of types, output function name, parameter list information;For statement type, output statement keyword, expression formula information;For letter Single categorical variable statement, output variable type, variable name;For the statement of complex structure body categorical variable, export structure body class Type, title, each sub- member variable types and name information.
5. a kind of syntax tree stratification method for expressing as claimed in claim 1, it is characterised in that:After the step 4, in addition to Following steps:The corresponding XML file of syntax tree is read, and draws the tree structure of syntax tree, the node of syntax tree is clicked/double-click When, according to the filename of record and row, column information, source file is directly opened, and highlight the corresponding character zone of display.
CN201710200792.0A 2017-03-30 2017-03-30 A kind of syntax tree stratification method for expressing Pending CN107133027A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201710200792.0A CN107133027A (en) 2017-03-30 2017-03-30 A kind of syntax tree stratification method for expressing

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201710200792.0A CN107133027A (en) 2017-03-30 2017-03-30 A kind of syntax tree stratification method for expressing

Publications (1)

Publication Number Publication Date
CN107133027A true CN107133027A (en) 2017-09-05

Family

ID=59715939

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201710200792.0A Pending CN107133027A (en) 2017-03-30 2017-03-30 A kind of syntax tree stratification method for expressing

Country Status (1)

Country Link
CN (1) CN107133027A (en)

Cited By (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107644073A (en) * 2017-09-18 2018-01-30 广东中标数据科技股份有限公司 A kind of field consanguinity analysis method, system and device based on depth-first traversal
CN108388577A (en) * 2018-01-17 2018-08-10 链家网(北京)科技有限公司 A kind of method and system automatically generating house floor plan syntax tree
CN108804105A (en) * 2018-04-13 2018-11-13 南京南瑞继保电气有限公司 A kind of program organization unit process of compilation method
CN109857662A (en) * 2019-01-25 2019-06-07 浙江数链科技有限公司 Case data processing method, device, computer equipment and storage medium
CN109976760A (en) * 2017-12-27 2019-07-05 北京东土科技股份有限公司 A kind of the cross compile method and cross-compiler of graphic language
CN110032363A (en) * 2019-03-21 2019-07-19 深圳点猫科技有限公司 A kind of data structure construction method and system for robotic programming
CN110096709A (en) * 2019-05-07 2019-08-06 百度在线网络技术(北京)有限公司 Command processing method and device, server and computer-readable medium
CN110928550A (en) * 2019-11-19 2020-03-27 上海工程技术大学 Method for eliminating redundancy of GCC abstract syntax tree based on keyword Trie tree
CN116976286A (en) * 2023-09-22 2023-10-31 北京紫光芯能科技有限公司 Method and device for text layout, electronic equipment and storage medium

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101261602A (en) * 2008-04-08 2008-09-10 杭州电子科技大学 Program correctness verification method based on syntax tree
CN102339252A (en) * 2011-07-25 2012-02-01 大连理工大学 Static state detecting system based on XML (Extensive Makeup Language) middle model and defect mode matching
CN103645986A (en) * 2013-11-29 2014-03-19 北京广利核系统工程有限公司 Generation method and reconstruction method of visualization syntax tree of compiler

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101261602A (en) * 2008-04-08 2008-09-10 杭州电子科技大学 Program correctness verification method based on syntax tree
CN102339252A (en) * 2011-07-25 2012-02-01 大连理工大学 Static state detecting system based on XML (Extensive Makeup Language) middle model and defect mode matching
CN103645986A (en) * 2013-11-29 2014-03-19 北京广利核系统工程有限公司 Generation method and reconstruction method of visualization syntax tree of compiler

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
"刘春燕" 等: ""基于关系语法树的C/C++代码静态检测方法研究"", 《计算机工程与设计》 *

Cited By (13)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107644073A (en) * 2017-09-18 2018-01-30 广东中标数据科技股份有限公司 A kind of field consanguinity analysis method, system and device based on depth-first traversal
CN109976760A (en) * 2017-12-27 2019-07-05 北京东土科技股份有限公司 A kind of the cross compile method and cross-compiler of graphic language
CN108388577A (en) * 2018-01-17 2018-08-10 链家网(北京)科技有限公司 A kind of method and system automatically generating house floor plan syntax tree
CN108804105B (en) * 2018-04-13 2022-02-18 南京南瑞继保电气有限公司 Program organization unit compiling processing method
CN108804105A (en) * 2018-04-13 2018-11-13 南京南瑞继保电气有限公司 A kind of program organization unit process of compilation method
CN109857662A (en) * 2019-01-25 2019-06-07 浙江数链科技有限公司 Case data processing method, device, computer equipment and storage medium
CN110032363B (en) * 2019-03-21 2023-07-07 深圳点猫科技有限公司 Data structure construction method and system for robot programming
CN110032363A (en) * 2019-03-21 2019-07-19 深圳点猫科技有限公司 A kind of data structure construction method and system for robotic programming
CN110096709A (en) * 2019-05-07 2019-08-06 百度在线网络技术(北京)有限公司 Command processing method and device, server and computer-readable medium
CN110928550A (en) * 2019-11-19 2020-03-27 上海工程技术大学 Method for eliminating redundancy of GCC abstract syntax tree based on keyword Trie tree
CN110928550B (en) * 2019-11-19 2023-11-24 上海工程技术大学 Method for eliminating GCC abstract syntax tree redundancy based on keyword Trie tree
CN116976286A (en) * 2023-09-22 2023-10-31 北京紫光芯能科技有限公司 Method and device for text layout, electronic equipment and storage medium
CN116976286B (en) * 2023-09-22 2024-02-27 北京紫光芯能科技有限公司 Method and device for text layout, electronic equipment and storage medium

Similar Documents

Publication Publication Date Title
CN107133027A (en) A kind of syntax tree stratification method for expressing
Collard et al. Lightweight transformation and fact extraction with the srcML toolkit
CN102609451B (en) SQL (structured query language) query plan generation method oriented to streaming data processing
JP5123291B2 (en) Generic interface for deep embedding of expression trees in programming languages
Fritzson et al. The open source Modelica project
Hogenboom et al. RDF-GL: a SPARQL-based graphical query language for RDF
CN110222318A (en) Data generating tool development approach based on XML
Zanoni Data mining techniques for design pattern detection.
CN110209389A (en) A kind of data generating tool development system based on XML
Anlauff et al. Formal aspects of and development environments for montages
CN114528846A (en) Concept network for artificial intelligence and generation method thereof
CN110460461A (en) Mapping method and system of the YANG pattern language to order line
Maletic et al. Leveraging XML technologies in developing program analysis tools
Nisbet et al. Presentations of rase knowledge mark-up
Bartman et al. srcQL: A syntax-aware query language for source code
Dongilli et al. An Intelligent Query Interface with Natural Language Support.
Steel et al. Generating human-usable textual notations for information models
CN112115615A (en) SCR-oriented safety key system model conversion method, device and system
Gapeyev et al. Statically typed document transformation: An Xtatic experience
Collard Meta-differencing: An infrastructure for source code difference analysis
Kosanović et al. Applang–A DSL for specification of mobile applications for android platform based on textX
Cardei et al. Framework for requirements-driven system design automation
Vajk et al. Raising the abstraction of domain-specific model translator development
Zhou et al. Implementation of G Language
Schordan et al. Specifying transformation sequences as computation on program fragments with an abstract attribute grammar

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
WD01 Invention patent application deemed withdrawn after publication

Application publication date: 20170905

WD01 Invention patent application deemed withdrawn after publication