200 likes | 373 Views
M.Sc. of Advanced Software Engineering CO7206 System Reengineering XML & AST Many Slides are by Georgios Koutsoukos. Objectives. To give some knowledge about core technologies used in CARE This lecture covers: XML AST. Outline. What is XML How can XML be used
E N D
M.Sc. of Advanced Software EngineeringCO7206System Reengineering XML & AST Many Slides are by Georgios Koutsoukos
Objectives • To give some knowledge about core technologies used in CARE • This lecture covers: • XML • AST
Outline • What is XML • How can XML be used • The importance of XML and its use in CARE • What is an AST • AST example and its importance in CARE
Related Readings • Al-Ekram & Kontogiannis, An XML-based Framework for Language Neutral Program Representation and Generic AnalysisAvailable at: • http://swag.uwaterloo.ca/~rekram/publications/csmr2005--xml-based-framework-for-language-neutral-program-representation-and-analysis.pdf • Useful links: • http://www.w3schools.com/xml/default.asp • http://www.mulberrytech.com/quickref/XMLquickref.pdf
What is XML • XML stands for eXtensible Markup Language • XML is a markup language much like HTML • XML is used to describe structured data • XML data is stored in plain-text format i.e software and hardware-independent • XML tags are not predifined. One must define its own tags. • XML may use a Document Type Definition (DTD) or an XML Schema to describe the data
XML Vs HTML • XML and HTML were designed with different goals: • XML was designed to describe data and to focus on what data is. • HTML was designed to display data and to focus on how data looks. HTML tags are predifined
How can XML be used • XML can be used to: • Separate data from its presentation • Exchange data between incompatible systems • Share data between different applications • Store data • In fact, currently XML is the de-facto standard in many software application areas such as Web content description, Web-Services and Communication Protocols (e.g SOAP) among many others.
XML Syntax (1) • XML Declaration contains: • Version of the XML specification • Character encoding of the document • XML Tags must: • Be case sensitive • Start with letter or underscore • Not contain whitespaces • Have an end Tag
XML Syntax (2) • Element Declaration • Elements must be properly nested • All XML documents must have a root element • Attribute Declaration • Atributes provide metadata for the element • Atributes must be enclosed in “” with no commas between • Same naming conventions as elements
An XML example The following is a very simple example of an XML document representing data of pets: <?xml version="1.0" encoding="iso-8859-1"?><pets> <pet type="dog" color="brown">Max</pet> <pet type="cat" color="white">Toula</pet> </pets>
XML and L-CARE Why should one care about XML in order to use L-CARE? In fact one does not have to care about XML, but about XPath which is the language for identifying parts of XML documents. L-CARE uses the XPath language in order to write markers for identifying patterns of code.XPath shall be explained in a future class.
What is an AST • AST stands for Abstract Syntax Tree • Abstract Syntax Trees are the basic source code representations at the finest level of granularity. • AST representation provides the most detailed information from the source code.
AST example (1) • An XML document can be viewed as an AST containing different kinds of nodes with the most widely used being the root, elements, attributes and text. For the XML example given before, the tree structure is showed in the following slide:
AST and CARE Why should one care about AST in order to use L-CARE? AST is a graphical form of representing the souce code in CARE and understanding it can be great, not only to understand the source code you are working on, but also to help you build XPath queries.
The following piece of code: public void tick() { theCurrentTime = Calendar.getInstance() ; if(theCurrentTime!=null){ notifyObservers(); } }
Could be represented in XML as (1): <Method ID="1084"> <Modifier value="public"/> <Type name="void"/> <Name value="tick"/> <Statements> <Assignment operator="="> <Name value="theCurrentTime"/> <Expression> <FunctionOp> <DotOp> <Name value="Calendar"/> <Name value="getInstance"/> </DotOp> </FunctionOp> </Expression> </Assignment>
Could be represented in XML as (2): <If> <Expression> <BinaryOp value="!="> <Name value="theCurrentTime"/> <Literal value="null"/> </BinaryOp> </Expression> <Then> <FunctionOp> <Name value="notifyObservers"/> </FunctionOp> </Then> </If> </Statements> </Method>
Key Points • XML is used by many tools as an attempt to describe data in an Universal way. • XML is used in CARE to represent source code and make marking and transforming it easier and more performant. • ASTs are graphical representations of source code and are useful to understand it. • There is a close connection between an XML representation and the corresponding AST.