26
INTERPRETING IMPERATIVE PROGRAMMING LAGUAGES IN EXTENSIBLE STYLESHEET LANGUAGE TRANSFORMATIONS (XSLT) Authors: Ruhsan Onder ([email protected]) Assoc. Prof. Dr. Zeki Bayram ([email protected])

INTERPRETING IMPERATIVE PROGRAMMING LAGUAGES IN EXTENSIBLE STYLESHEET LANGUAGE TRANSFORMATIONS (XSLT) Authors: Ruhsan Onder ([email protected]) Assoc

Embed Size (px)

Citation preview

Page 1: INTERPRETING IMPERATIVE PROGRAMMING LAGUAGES IN EXTENSIBLE STYLESHEET LANGUAGE TRANSFORMATIONS (XSLT) Authors: Ruhsan Onder (ruhsan.onder@emu.edu.tr) Assoc

INTERPRETING IMPERATIVE PROGRAMMING LAGUAGES IN

EXTENSIBLE STYLESHEET LANGUAGE TRANSFORMATIONS (XSLT)

Authors:

Ruhsan Onder

([email protected])

Assoc. Prof. Dr. Zeki Bayram

([email protected])

Page 2: INTERPRETING IMPERATIVE PROGRAMMING LAGUAGES IN EXTENSIBLE STYLESHEET LANGUAGE TRANSFORMATIONS (XSLT) Authors: Ruhsan Onder (ruhsan.onder@emu.edu.tr) Assoc

OUTLINE Overview of work done

XML based basic imperative language XIM

Interpreter for XIM in XSLT

Possible application areas

Demonstration of a simple XIM code in execution

Related work (XML based languages and their interpreters)

Conclusion and future work

References

Page 3: INTERPRETING IMPERATIVE PROGRAMMING LAGUAGES IN EXTENSIBLE STYLESHEET LANGUAGE TRANSFORMATIONS (XSLT) Authors: Ruhsan Onder (ruhsan.onder@emu.edu.tr) Assoc

OVERVIEW OF WORK DONE

XML based basic imperative language XIM

XIM; An XML based simple imperative language with basic constructs

Assignment Loop (while) Conditional (if)

Basic Arithmetic/Logic Operations

Syntax description of XIM in XML Schema

Interpretation, using XSLT

Page 4: INTERPRETING IMPERATIVE PROGRAMMING LAGUAGES IN EXTENSIBLE STYLESHEET LANGUAGE TRANSFORMATIONS (XSLT) Authors: Ruhsan Onder (ruhsan.onder@emu.edu.tr) Assoc

Pseudo algorithm of a sample XIM program to compute 5!

var fact ←1

var last ←5

begin

while (last>1) do

fact ←fact*last

last ←last-1

end while

end

Page 5: INTERPRETING IMPERATIVE PROGRAMMING LAGUAGES IN EXTENSIBLE STYLESHEET LANGUAGE TRANSFORMATIONS (XSLT) Authors: Ruhsan Onder (ruhsan.onder@emu.edu.tr) Assoc

XIM code to compute 5!

<program> <vars> <var_declare name="fact"> 1 </var_declare> <var_declare name="last"> 5 </var_declare> </vars> <main> <while> <condition> <boolop opname="gt"> <var_use name="last"/> <num> 1 </num> </boolop> </condition> <statement_list> <assign varn="fact"> <op opname="*"> <var_use name="fact"/> <var_use name="last"/> </op> </assign> <assign varn="last"> <op opname="-"> <var_use name="last"/> <num> 1</num> </op> </assign> </statement_list> </while> <end/> <!-- program termination --> </main> </program>

Page 6: INTERPRETING IMPERATIVE PROGRAMMING LAGUAGES IN EXTENSIBLE STYLESHEET LANGUAGE TRANSFORMATIONS (XSLT) Authors: Ruhsan Onder (ruhsan.onder@emu.edu.tr) Assoc

Graphical representation of execution process

XIM source code(XML doc.)

Initializer stylesheet for sequencing

Initializerstylesheet forattaching next info.

XIM source code withSeq. info

applier

applier

XIM code withSeq. & next info

applier

Resulting XIM code after execution of an instruction

Interpreter Stylesheet

Step 1

Step 2

Step 3

loop

loop

Page 7: INTERPRETING IMPERATIVE PROGRAMMING LAGUAGES IN EXTENSIBLE STYLESHEET LANGUAGE TRANSFORMATIONS (XSLT) Authors: Ruhsan Onder (ruhsan.onder@emu.edu.tr) Assoc

XIM code after the application of 1st

Initializer Stylesheet

<prog> <memory> <var_declare name="fact"> 1 </var_declare> <var_declare name="last"> 5 </var_declare> <var_declare name="PC"> 1 </var_declare> </memory> <main> <while seq="1"> <condition> <boolop opname="gt"> <var_use name="last" /> <num> 1</num> </boolop> </condition> <statement_list seq="6"> <assign varn="fact“ seq="7"> <op opname="*"> <var_use name="fact" /> <var_use name="last" /> </op> </assign> <assign varn="last" seq="11"> <op opname="-"> <var_use name="last" /> <num> 1 </num> </op> </assign> </statement_list> </while> <end seq="15“/> </main> </prog>

Page 8: INTERPRETING IMPERATIVE PROGRAMMING LAGUAGES IN EXTENSIBLE STYLESHEET LANGUAGE TRANSFORMATIONS (XSLT) Authors: Ruhsan Onder (ruhsan.onder@emu.edu.tr) Assoc

XIM code after the application of 2nd

Initializer Stylesheet

<prog> <memory> <var_declare name="fact"> 1 </var_declare> <var_declare name="last"> 5 </var_declare> <var_declare name="PC"> 1 </var_declare> </memory> <main> <while seq="1" next="15"> <condition true_next="6" false_next="15"> <boolop opname="gt"> <var_ use name="last" /> <num> 1 </num> </boolop> </condition> <statement_list seq="6" next="1"> <assign varn="fact" seq="7" next="11"> <op opname="*"> <var_use name="fact" /> <var_use name="last" /> </op> </assign> <assign varn="last" seq="11" next="1"> <op opname="-"> <var_use name="last" /> <num> 1 </num> </op> </assign> </statement_list> </while> <end seq="15“/> </main> </prog>

Page 9: INTERPRETING IMPERATIVE PROGRAMMING LAGUAGES IN EXTENSIBLE STYLESHEET LANGUAGE TRANSFORMATIONS (XSLT) Authors: Ruhsan Onder (ruhsan.onder@emu.edu.tr) Assoc

The Applier Program

Pseudo algorithm of the C#.NET applier program

1. result tree ← XML document formed by the application of

the initializer stylesheets to the original XIM

program

2. While (the instruction to execute in result tree is not the <end> element)

result tree ← result of applying the interpreter stylesheet to result tree

End While

3. Display the contents of the <memory> element

Page 10: INTERPRETING IMPERATIVE PROGRAMMING LAGUAGES IN EXTENSIBLE STYLESHEET LANGUAGE TRANSFORMATIONS (XSLT) Authors: Ruhsan Onder (ruhsan.onder@emu.edu.tr) Assoc

Applier (cont.)

Written in C# .NET

DOM is utilized for the traversal To check whether the instruction to be executed is an <end> statement

Page 11: INTERPRETING IMPERATIVE PROGRAMMING LAGUAGES IN EXTENSIBLE STYLESHEET LANGUAGE TRANSFORMATIONS (XSLT) Authors: Ruhsan Onder (ruhsan.onder@emu.edu.tr) Assoc

Implementation of the XSLT Interpreter

A named template for each construct

A recursive named template for artihmetic / logic operations

Expressions; infix binary trees Evaluator template calls itself until it comes to a leaf

node which is a numeric literal or a variable

To keep the sequence of the instruction to be executed

@seq, @next, @true_next, @false_next attributes

A program counter (PC) is maintained by the interpreter

Page 12: INTERPRETING IMPERATIVE PROGRAMMING LAGUAGES IN EXTENSIBLE STYLESHEET LANGUAGE TRANSFORMATIONS (XSLT) Authors: Ruhsan Onder (ruhsan.onder@emu.edu.tr) Assoc

Pseudo algorithm of the interpreter

Match the instruction whose @seq is equal to the number in PC

Call the template which decides the type of instruction

and calls the corresponding template The matched instruction node sent as a parameter to the

corresponding templates

Upon the return of the called template copy the main part of the XIM code

P.S. Matching facility of XSLT & XPath queries utilized to

find the instruction to be executed

access the user defined variables in memory

Page 13: INTERPRETING IMPERATIVE PROGRAMMING LAGUAGES IN EXTENSIBLE STYLESHEET LANGUAGE TRANSFORMATIONS (XSLT) Authors: Ruhsan Onder (ruhsan.onder@emu.edu.tr) Assoc

Pseudo algorithm of the templates

Assignment Template Copy all the variables in memory except PC and

the one to whom a new value to be assigned

Call template for evaluation of the expression to be

assigned

Recreate the variable with its new assigned value

Recreate the PC with its new value as the @next of the current instruction

Page 14: INTERPRETING IMPERATIVE PROGRAMMING LAGUAGES IN EXTENSIBLE STYLESHEET LANGUAGE TRANSFORMATIONS (XSLT) Authors: Ruhsan Onder (ruhsan.onder@emu.edu.tr) Assoc

Template for Conditional (If) and Loop (While)

Evaluate the condition

Copy all other elements in the memory other than PC unchanged

If the condition is true Update PC as @true_next of the current instruction

Else Update PC as @false_next of the current instruction

P.S. The distinction between If and While made by the

initializer stylesheet during the insertion of @next attributes

Page 15: INTERPRETING IMPERATIVE PROGRAMMING LAGUAGES IN EXTENSIBLE STYLESHEET LANGUAGE TRANSFORMATIONS (XSLT) Authors: Ruhsan Onder (ruhsan.onder@emu.edu.tr) Assoc

POSSIBLE APPLICATION AREAS Delivery of executable content over internet together

with its executer With the combined initializers and the interpreter into a

single styleseet to provide single-step execution

This approach opens the way for the development of applications compatible with any browser.

A standard XSLT processor implemented in every browser

XIM can be improved to create a distributed computing web service application

For use in special purpose computations requiring intensive CPU usage

Upon the requests of the user through a GUI, constructed XIM prog. can be sent to the client by the server together with the interpreter

Page 16: INTERPRETING IMPERATIVE PROGRAMMING LAGUAGES IN EXTENSIBLE STYLESHEET LANGUAGE TRANSFORMATIONS (XSLT) Authors: Ruhsan Onder (ruhsan.onder@emu.edu.tr) Assoc

Scripting program running on web server

ServerWeb Browser

Client

User request sent by the browser

XIM code constructed according to the the user request

+XSLT interpreter

Requested operation and parameters from user

Execution of incoming XIM code using the incoming interpreter

Step 1:

Step 2 :

Step 3:

Step 4:

For a computation intensive application

Page 17: INTERPRETING IMPERATIVE PROGRAMMING LAGUAGES IN EXTENSIBLE STYLESHEET LANGUAGE TRANSFORMATIONS (XSLT) Authors: Ruhsan Onder (ruhsan.onder@emu.edu.tr) Assoc

Semantic Web is the name of a new emerging diversion of the current Web, but unlike the current version it aims to implement machine-readable-structured information oriented version of Web.

Ideas of the interpreter can be developed to implement an XSLT inference engine for semantic web

Through the reasoning of ontologies by XSLT, an XML decision tree can be created

APPLICATION AREAS (contd.)

Page 18: INTERPRETING IMPERATIVE PROGRAMMING LAGUAGES IN EXTENSIBLE STYLESHEET LANGUAGE TRANSFORMATIONS (XSLT) Authors: Ruhsan Onder (ruhsan.onder@emu.edu.tr) Assoc

XIM code after the application of 2nd

Initializer Stylesheet

<prog> <memory> <var_declare name="fact"> 1 </var_declare> <var_declare name="last"> 5 </var_declare> <var_declare name="PC"> 1 </var_declare> </memory> <main> <while seq="1" next="15"> <condition true_next="6" false_next="15"> <boolop opname="gt"> <var_ use name="last" /> <num> 1 </num> </boolop> </condition> <statement_list seq="6" next="1"> <assign varn="fact" seq="7" next="11"> <op opname="*"> <var_use name="fact" /> <var_use name="last" /> </op> </assign> <assign varn="last" seq="11" next="1"> <op opname="-"> <var_use name="last" /> <num> 1 </num> </op> </assign> </statement_list> </while> <end seq="15“/> </main> </prog>

Page 19: INTERPRETING IMPERATIVE PROGRAMMING LAGUAGES IN EXTENSIBLE STYLESHEET LANGUAGE TRANSFORMATIONS (XSLT) Authors: Ruhsan Onder (ruhsan.onder@emu.edu.tr) Assoc

DEMONSTRATION

Execution steps after the interpreter stylesheet is applied

<var_declare name="fact"> 1 </var_declare><var_declare name="last"> 5 </var_declare><var_declare name="PC"> 6 </var_declare>

after the 1st application of the interpreter stylesheet

<var_declare name="fact">5</var_declare><var_declare name="last"> 5 </var_declare><var_declare name="PC">11</var_declare>

after the execution of the first assignment statement in the loop

<var_declare name="fact">5</var_declare><var_declare name="last">4</var_declare><var_declare name="PC">1</var_declare>

after $last decremented and PC is updated as 1 to loop

Page 20: INTERPRETING IMPERATIVE PROGRAMMING LAGUAGES IN EXTENSIBLE STYLESHEET LANGUAGE TRANSFORMATIONS (XSLT) Authors: Ruhsan Onder (ruhsan.onder@emu.edu.tr) Assoc

Execution demo (cont.)

<var_declare name="fact">5</var_declare><var_declare name="last">4</var_declare><var_declare name="PC">6</var_declare>

condition of <while> is satisfied and PC gets value of @true_next

<var_declare name="fact">20</var_declare><var_declare name="last">4</var_declare><var_declare name="PC">11</var_declare>

$fact = $fact * $last

<var_declare name="fact">20</var_declare><var_declare name="last">3</var_declare><var_declare name="PC">1</var_declare>

$last is decremented and PC becomes 1 to loop

Page 21: INTERPRETING IMPERATIVE PROGRAMMING LAGUAGES IN EXTENSIBLE STYLESHEET LANGUAGE TRANSFORMATIONS (XSLT) Authors: Ruhsan Onder (ruhsan.onder@emu.edu.tr) Assoc

Execution demo (cont.)

<var_declare name="fact">120</var_declare><var_declare name="last">1</var_declare><var_declare name="PC">1</var_declare>

$last is decremented and PC becomes 1 to loop

<var_declare name="fact">120</var_declare><var_declare name="last">1</var_declare><var_declare name="PC">15</var_declare>

Sample program after the applier program terminates. Condition of <while> evaluates to false and PC gets value of @false_next to terminate loop

Page 22: INTERPRETING IMPERATIVE PROGRAMMING LAGUAGES IN EXTENSIBLE STYLESHEET LANGUAGE TRANSFORMATIONS (XSLT) Authors: Ruhsan Onder (ruhsan.onder@emu.edu.tr) Assoc

RELATED WORK

An XML based scripting language and its interpreter in C++ [Arciniegas 2001]

X-VRML ; An XML based language for modeling virtual reality whose interpeter is developed in Java [Walczak, Cellary 2002]

XPEN ; An XML based format for distributed online handwriting recognition. Processing of it via a programming languagage through DOM [Lenaghan, Malyan 2003]

A lazy XML parser via the implementation of lazy XSL transformations [Schott, Noga 2003]

Page 23: INTERPRETING IMPERATIVE PROGRAMMING LAGUAGES IN EXTENSIBLE STYLESHEET LANGUAGE TRANSFORMATIONS (XSLT) Authors: Ruhsan Onder (ruhsan.onder@emu.edu.tr) Assoc

CONCLUSION AND FUTURE WORK

Operational Semantics of a simple XML based imperative language (XIM) is implemented in XSLT

Execution of code through iterative application of the interpreter to the code

Current work

Improving the interpreter for single-application to proivde for the delivery of a XIM program over Internet according to a user’s requirements, together with its data and interpreter

Future work Implementation of denotational semantics of XIM by translating XIM

programs into lambda calculus and interpreting the lambda calculus code using XSLT (web service semantics)

Future Research XSLT inference engine for semantic web

Page 24: INTERPRETING IMPERATIVE PROGRAMMING LAGUAGES IN EXTENSIBLE STYLESHEET LANGUAGE TRANSFORMATIONS (XSLT) Authors: Ruhsan Onder (ruhsan.onder@emu.edu.tr) Assoc

Improvement to the interpreter

Execution at a single step without the applier program

Initializers and interpreter are combined into a single stylesheet

Via the use of temporary result-tee fragments (can be assigned to an XSLT variable)

Stylesheet is declared in the source code using :

<? xml:stylesheet type="text/xsl" href="interp.xsl“ ?>

Step by step execution is better for tracing

Page 25: INTERPRETING IMPERATIVE PROGRAMMING LAGUAGES IN EXTENSIBLE STYLESHEET LANGUAGE TRANSFORMATIONS (XSLT) Authors: Ruhsan Onder (ruhsan.onder@emu.edu.tr) Assoc

REFERENCES

1. w3c.org recommendations for XML, XML Schema, XSLT, XPath

2. F. A. Arciniegas. Creating C++ interpreters for XML extension languages. http://www.informit.com/articles/article.asp?p=23277, September 2001.

3. K. Walczak and W. Cellary. X-VRML – XML based modeling of virtual reality. Proceedings of the 2002 symposium on applications and the internet

(SAINT’02), pages 204–213, 2002.

4. K.P. Lenaghan and R.R. Malyan. XPEN: An XML based format for distributed online handwriting recognition.Proceedings of the seventh international conference on document analysis and recognition (ICDAR’03), pages 1270–1274, 2003.

5. S. Schott and M. L. Noga. Lazy XSL transformations. Proceedings of the 2003 ACM symposium on Document engineering, pages 9–18, 2003.

Page 26: INTERPRETING IMPERATIVE PROGRAMMING LAGUAGES IN EXTENSIBLE STYLESHEET LANGUAGE TRANSFORMATIONS (XSLT) Authors: Ruhsan Onder (ruhsan.onder@emu.edu.tr) Assoc

QUESTIONS

?