Programming Languages and Translators COMS W4115 Prof Stephen Edwards TweaXML Final Report By Kaushal Kumar kk2457 columbia edu Srinivasa Valluripalli sv2232 columbia edu Contents 1 Introduction 3 Abstract Introduction 2 Language Features 4 3 Language Tutorial 6 4 Language Manual 10 5 Project Plan 23 Project Processes Project Timeline Roles and Responsibilities Software Development Environment Project Log 6 Architectural Design 26 7 Test Plan 27 8 Lessons Learned 30 9 Appendix 31 Code Listing 1 Introduction Abstract In this document we present the description tutorial sample programs and test classes for TweaXML a high level language for manipulation of XML documents We will discuss the motivation behind the idea and key features of the language Introduction TweaXML is a simple language that helps us manipulate and perform various operations on XML documents like extracting specific data performing arithmetic string operations on the extracted data and saving the data in a desired format to a file The Extensible Markup Language XML is a general purpose markup language It is classified as an extensible language because it allows the users to define their own tags XML is designed primarily to share information across heterogeneous systems regardless of the specific architecture or language of the systems It is adopted as an interoperable language across various technologies and component vendors for example it is used to share data across J2EE components and NET components Since XML is highly customizable and contains user defined tags the technologies to parse an XML document are quite complex For example Java provides APIs like SAX and DOM Parsers to parse XML documents but they are quite complex and require a thorough knowledge of Java Therefore we have implemented TweaXML a language which will be easy to use and will require minimal amount of a prior knowledge of programming to get started right away TweaXML will enable a novice user to manipulate and operate on XML documents extract its data and do arithmetic string operations on it and save it in a desired format 2 Language Features Data Types string Data type containing data of character and string types file Data type for writing file on a file system node Data type for a XML element int Standard int data type Operators Arithmetic Operators addition subtraction multiplication division assignment equal greater than less than greater than or equal to less than or equal to not equal to Scope Operators comment Looping constructs If else While FOREACH Methods available on STRING NODE and FILE data types STRING If the string variable represents a number arithmetic operations can be done on it using following inbuilt functions add str1 str2 adds two numbers Concatenates them if both of them are not numbers subtract str1 str2 subtracts the two numbers represented by str1 and str2 It throws a runtime exception if they are not numbers multiply str1 str2 multiplies the two numbers represented by str1 and str2 It throws a runtime exception if they are not numbers divide str1 str2 divide the two numbers represented by str1 and str2 It throws a runtime exception if they are not numbers NODE getchild node path to child node gives an arraylist of child nodes defined by xpath given as the 2nd argument length nodes gives the number of nodes present in the nodes array getvalue node gives the value of the node in string format FILE open path of input file opens the input xml file to read and returns the root node create path of output file creates an output file to write and returns a file data type Close file name closes the output file after all the operations are done 3 Language Tutorial TweaXML is designed to handle XML files extract data from it do arithmetic string operations on it and write the data in an output format in desired format This tutorial will help programmers learn TweaXML as quickly and easily as possible Before we get started on the programs lets look at the input file for the following set of the programs students student name kaushal name homework1 85 homework1 homework2 85 homework2 midterm 70 midterm final 90 final student student name Srini name homework1 80 homework1 homework2 85 homework2 midterm 87 midterm final 95 final student students This input file contains the information about each student s marks in a class for various exams The final aim is to parse this input xml file and extract the data and calculate average marks of each student 2 1 TweaXML program This program shows how to open an XML file to read extract the child nodes of a node and get the value of a node Also it will show how to use various statements like if else while etc start file output node rootNode output create AvgMarks csv rootNode open marks data xml node studentNodes studentNodes getchild rootNode student int len len length studentNodes if len 0 int j j 0 while j len node nameNode homework1Node homework2Node midtermNode finalNode string name homework1Marks homework2Marks midtermMarks finalMarks nameNode getchild studentNodes j name homework1Node getchild studentNodes j homework1 homework2Node getchild studentNodes j homework2 midtermNode getchild studentNodes j midterm finalNode getchild studentNodes j final name getvalue nameNode 0 homework1Marks getvalue homework1Node 0 homework2Marks getvalue homework2Node 0 midtermMarks getvalue midtermNode 0 finalMarks getvalue finalNode 0 string totalMarks totalMarks add homework1Marks homework2Marks totalMarks add totalMarks midtermMarks totalMarks add totalMarks finalMarks string avgMarks avgMarks divide totalMarks 4 print output name print output t print output avgMarks print output n j j 1 close output Program start All TweaXML programs are contained within start statement So the program starts on line 1 with start statement Declarations All the variables should be declared before a value can be assigned to them Example of declarations for various data types file output node rootNode node studentNodes int len string totalMarks if statement If statement takes an expression as a parameter which should evaluate to true or false while statement while statement takes an expression as a parameter which should evaluate to true or false If expression evaluates to true the loop will be executed otherwise not Opening an input xml file to read rootNode open marks data xml open statement can be used to open an input file to read It returns the root node of the xml file which can be used later in the
View Full Document
Unlocking...