| The communication between the upper computer and the lower computer in electrochemical instruments is vital important to data transmission. The development of communication protocols is vital important to accuracy and effectiveness of data transmission between the upper computer and the lower computer.It is the purpose of this thesis that developing a full set of encoders and decoders of communication protocol of the upper computer and the lower computer in electrochemical instruments. For the research direction of Domain-Specific Language, it eliminates the defects such as redundancy and ambiguities forming into a context-free rules from communication protocols in electrochemical instruments described by natural language. At the same time, the implementation of automatic generation of 128 encoders and decoders of 32 kinds of experimental methods in SECM using ANTLR and String Template, improving the efficiency and quality of code generation, as well as expansibility and maintainability of the project.Different experiments are expressed as different input files, based on well defined communication protocols. Experimental data such as names, parameters, types of parameters, are extracted from input files, via lexical parsers and grammar parsers implements by ANTRL, saving as hierarchically nested data structures. The data are rendered by String Template to encoders, decoders and related test codes.The project consists of launch module, input module, parse module, control module and render module. Launch module, implemented by different script technology to meet the need of crossing platforms, sets environment variables, compiles classes and launches the entry function. Input module provides experimental data, organized by a file per experiment, written based on well defined protocols, to meet the need of multiple experiments. Parse module consisting of the lexical parser and the grammar parser, extracts experimental data from the input module and provides the data to the data defined classes of the control module. Control module organizes the data by related data to pass the data to the render module and includes the main process of the project. Render module render the templates to source codes with loading the experimental data. |