Font Size: a A A

A Conversion From Java Language To XML

Posted on:2006-05-31Degree:MasterType:Thesis
Country:ChinaCandidate:W S WangFull Text:PDF
GTID:2168360155453134Subject:Software engineering
Abstract/Summary:PDF Full Text Request
Nowadays, economy is fast-developing, people have higher requirements to the cost and efficiency. In order to break the constraint of platform to users, fully utilize the existing achievements, save expenses that train or develop, platform or datum migration is become more and more important. The classical plain-text representation of source code is convenient for programmers but requires parsing to uncover the deep structure of the program. While develop software tools to parse source code to gain access to the program's structure is more sophisticated. Because XML (Extensible Markup Language) can describe data and their structure information, so consider that reflecting the structure of the program in XML language and realizing the conversion among languages is feasible. This subject studied how to convert Java language into XML, that is to say representing Java programs in XML language, mainly focus on the representation of their structure, as thus establish the foundation of converting Java into other languages. And based on this representation, we can easily do the further works by leveraging the abundance of XML tools and techniques that already exists. Before converting, we needed to acquire the relevant knowledge, such as the knowledge of JavaCC (Java Compiler Compiler) , abstract syntax tree (AST) and relevant compiler knowledge, program structure and design techniques of Java, knowledge of XML and DTD , knowledge of the design pattern. JavaCC is designed to accelerate the development course of the customer language parser. In its input file (.jj file), defines all the rules of a certain language, and .jjt file is the expansion of it, which contains the sentence to customizes the syntax tree. While introducing JavaCC tool, there also introduce the structure of .jjt and .jj file, and how to construct them, so that we can set up or revise them. The AST is the target we operate, which is corresponding to the course of deriving of carrying on syntactic analysis to the input of token string, can reflect the structure of the program. We should have a certain understanding to it. Because the AST of Java is got by utilizing the JavaCC tool, it is introduced briefly. To XML, because it is our goal language, we must master it. DTD is abbreviated of Document Type Definition, used for defining the form of XML files, it defines marks, attributes that can have and the order of these marks that may appear in a certain kind of XML files. It is the basis that we convert Java into XML according to, the file which accord with the DTD is valid, it is what we need. Consider the direction role of the DTD to our conversion work, we must grasp the grammar of DTD skillfully, in order to set up or revise it. So the introduce about XML and DTD is comparatively detailed in the article. Convert Java into XML is realized through operation on the nodes of the AST, because the data structure of the nodes is very stable, it is suitable to realize it via Visitor Pattern. Visitor Pattern separate the operations from data structure, it helps to expand the system, and convenient to add new visitors. There is an essential introduction about Visitor Pattern, yet about Java only simply mentioned. Based on the above knowledge, the conversion work we can start. Realize this conversion may be divided into three great steps: The first step is from Java to the abstract syntax tree, the second step is from the AST to XML, the third step examines performance of the conversion by some instances. In the first step, choose the Java1.0.2.jjt which has been tested strictly as the input file of JavaCC, set up the compiler (in the form of .java file) and the AST of Java. In the second step, at first, choose the DTD used, Java _ to _ XML DTD, and specified some typical marks how it defined, and the advantage of such definition. Then add semantic action and the 'accept'method to every class of node types of the AST according to the DTD. Here, semantic action defines the method of each type of nodes how they convert into corresponding XML code, in practice it is the course of outputting the marks and attributes of their corresponding XML forms according to the definition in DTD. Then set up the abstract visitor interface, visitor adapter...
Keywords/Search Tags:Conversion
PDF Full Text Request
Related items