use of attribute grammars to construct xml translators supervisor: prof. john hurst presenter:...
Post on 22-Dec-2015
212 Views
Preview:
TRANSCRIPT
Use of Attribute Grammars to Construct XML translators
Supervisor: Prof. John HurstSupervisor: Prof. John Hurst
Presenter: Nishan Jayasinghe Presenter: Nishan Jayasinghe
Project AimProject Aim
Existing XML Translator XSLTExisting XML Translator XSLT
Translator Writing TechniquesTranslator Writing Techniques
The Translators & Difficulties Encountered The Translators & Difficulties Encountered
What Was Learnt?What Was Learnt?
Future Work and ConclusionFuture Work and Conclusion
Overview
Project Aim Can we translate XML using attribute grammars?Can we translate XML using attribute grammars?
Is it simpler to translate XML with attribute Is it simpler to translate XML with attribute grammars compared to existing solutions?grammars compared to existing solutions?
Is it possible to create a simpler specification Is it possible to create a simpler specification language that represent attribute grammar language that represent attribute grammar computations?computations?
Existing XML Translator Most popular method for translating XML is XSLT Most popular method for translating XML is XSLT XML document and specification are used by XSL XML document and specification are used by XSL
processor to do the translationprocessor to do the translation
AdvantagesAdvantages Disadvantages Disadvantages Simple to update and Simple to update and maintain the XSLT maintain the XSLT specificationsspecifications Reuse specification using Reuse specification using by including other by including other specificationsspecifications
XSLT sXSLT specification pecification syntax is complicatedsyntax is complicated
Translator Writing Techniques
Subset of stages involved in constructing a compilerSubset of stages involved in constructing a compiler Lexical AnalysisLexical Analysis Syntax AnalysisSyntax Analysis Semantic AnalysisSemantic Analysis
Why use these techniques?Why use these techniques? These techniques have been applied to other These techniques have been applied to other
translator writing taskstranslator writing tasks Development time and effort shorterDevelopment time and effort shorter
Lexical Analysis
Break up input document into tokensBreak up input document into tokens Using Regular ExpressionUsing Regular Expression
<name> XML for Beginners </name><name> XML for Beginners </name>
StartName : <name>StartName : <name>
DATA :DATA : [A-Za-z]+[A-Za-z]+
EndName : </name>EndName : </name>
Syntax Analysis
Describes the document structureDescribes the document structure Using Context Free GrammarUsing Context Free Grammar
<book><book>
<name> XML for Beginners </name><name> XML for Beginners </name>
<author> J. Smith </author><author> J. Smith </author>
</book></book>
book: startBook name author endBook .book: startBook name author endBook .
name: startName DATA endName .name: startName DATA endName .
author: startAuthor DATA endAuthor .author: startAuthor DATA endAuthor .
Semantic Analysis Describes computations that should occur given a Describes computations that should occur given a
particular contextparticular context Using Attribute GrammarUsing Attribute Grammar
<name> XML for Beginners </name> <name> XML for Beginners </name>
Title: XML for BeginnersTitle: XML for Beginners UsingUsing
RULE: name ::= startName DATA endName COMPUTERULE: name ::= startName DATA endName COMPUTE
name.output = Concatenate( “Title:”, name.output = Concatenate( “Title:”, DATA);DATA);
END; END;
Input
(XML document)
Lexical Analysis Syntax Analysis Semantic Analysis
Output
(translated document)
Document Processing
The Translators
It is possible to translate XML documentsIt is possible to translate XML documents Created two translatorsCreated two translators
XML to HTMLXML to HTML
XML to TEXXML to TEX
Our HTML Translator Output
XSLT Output
Our TEX Translator Output
XSLT Output
Display On a web browser
Difficulties Encountered We found that the translators can not deal with the We found that the translators can not deal with the
following XSLT featuresfollowing XSLT features White space characters outside the character White space characters outside the character
data sections data sections
Changing of document structure from input Changing of document structure from input documentdocument
Length and complexity of CodeLength and complexity of Code
Code Size Example
XSLT Counting
<xsl:template match="enumerate"> <xsl:variable name=“depth" select="count(ancestor::enumerate)"/></xsl:template>
Attribute Grammar
ATTR depth: int INH;
RULE: document ::= DocType article COMPUTE document.depth = 0;END;
SYMBOL enumerate COMPUTE INH.depth = ADD(INCLUDING (enumerate.depth,document.depth), 1);END;
What Did We Learn? Writing Attribute Grammar translator is very time Writing Attribute Grammar translator is very time
consuming compared with XSLTconsuming compared with XSLT Difficult to learn some conceptsDifficult to learn some concepts The amount of code required for simple The amount of code required for simple
translator is not worth the efforttranslator is not worth the effort
But is possible to automatically generate (given But is possible to automatically generate (given the DTD) specifications using a simple algorithm the DTD) specifications using a simple algorithm forfor Lexical Analysis specificationLexical Analysis specification Syntax Analysis specificationSyntax Analysis specification
Algorithm for DTD to Lexical Specifications
<!ELEMENT book (name, author)><!ELEMENT book (name, author)>
<!ELEMENT name (#PCDATA)><!ELEMENT name (#PCDATA)>
<!ELEMENT author (#PCDATA)><!ELEMENT author (#PCDATA)>
Lexical Tokens
startBook : <book>
endBook : </book>
startName : <name>
endName : </name>
startAuthor : <author>
endAuthor : </author>
PCDATA : [A-Za-z]+
Algorithm for DTD to Syntax Specifications
<!ELEMENT book (name, author)><!ELEMENT book (name, author)>
<!ELEMENT name (#PCDATA)><!ELEMENT name (#PCDATA)>
<!ELEMENT author (#PCDATA)><!ELEMENT author (#PCDATA)>
Context Free Grammar
book : startBook name author endBook
name : startName PCDATA endName
author : startAuthor PCDATA endAuthor
Future Work Due to a lack of timeDue to a lack of time we could not create a we could not create a
specification language that can be used instead specification language that can be used instead of attribute grammars by usersof attribute grammars by users
Implement other XSLT functions such as sortImplement other XSLT functions such as sort
Try extending the automatic generation of Try extending the automatic generation of specifications to other types of document specifications to other types of document formatsformats
Conclusion We were able to translate XML documents using We were able to translate XML documents using
attribute grammarsattribute grammars
We were able to reduce most of the time required We were able to reduce most of the time required for developing attribute grammar translator using for developing attribute grammar translator using automatically generated specificationsautomatically generated specifications
It is clear at the moment XSLT is much simpler It is clear at the moment XSLT is much simpler specification language from writing translations specification language from writing translations
top related