uXML
An Experiment in Common Representation
of Different Programming Paradigms
                           Kunal S. Pathak
Outline

History              Extensibility

Objective            Drawbacks

Applications         Future Work

Architecture         Summary

Tools                Questions

Examples             Thank you
History

    Before UNCOL                After UNCOL

Programming                   Programming
                   Machines    languages        Machines
 languages


1                               1
                         1                                 1

2                               2           U
                        2                   N          2

3                               3           C
                         :
                                            O              :
:                               :
                        N
                                            L          N
M                               M
Examples of UNCOL

Sun’s Java framework


GNU Compiler Collection


Microsoft’s .NET and Phoenix
framework
Objective

Different from that of UNCOL
Design an XML schema (uXML) to
represent the semantics of different
programming paradigms
Test the uXML against various
programming languages
Develop tools that use uXML
Applications

Software Metric tool
Educational tool
Plug-n-play Programming Language
(specific paradigms)
Source language converter tool
Extract the program structure
Architecture

                             uXML format


C Program                <uXML language="abc"
                                  scope="static">
                                                                         Interpreter   Program
                                                                            (XV)        output
                        <function name="func">
P Program                  <returns type="void"/>
                           <block>
                           ...                       uXML
                           ...                      Schema
                                                     Valid-
                           </block>
J Program                                            ation
                        </function>
                           ...
                           ...


L Program               <call>
                          <variable name=”func” /                                      Software
                        >                                           Code Analysis      Metrics
                        </call>
Y Program                  ...
                        </uXML>


            Front end                                         Back end
Architecture cont.

Compiler framework - Activation record,
Symbol table, Display, Calling sequence,
Datatypes


Back end parser - uXML visitor


Front end parsers - C, P, J, L and Y
Tools in uXML


Code interpreter - xv
•   Visit uXML nodes and execute the
    respective code
Code analysis - xv, xsl
•   Count the appropriate uXML nodes
Why XML in uXML?

Program = Syntax tree = XML
Human understandable
Retains the semantics of the program
Many XML processing tools
- XSL, XSL-FO, XQuery, etc
Universally accepted
Few uXML elements

<var/>, <variable/>, <constant/>
<assign/>, <operator/>, <for-loop/>,
<iterate/>, <cast/>
<function/>, <class/>, <constructor/>,
<block/>, <call/>
‘scope’ and ‘var-declaration’ attribute of
<uXML/>
PL features handled by uXML

Iterations, if-else, arrays, pointers
Function definition/call, nested
procedures, functions as first-class
objects
Static vs. Dynamic Typing and Scoping
Classes, Constructors, Inheritance
Front end Parsers


C - Similar to Dennis Ritchie’s C
P - Similar to Niklaus Wirth’s Pascal
J - Similar to Sun Microsystem’s Java
L - Similar to John McCarthy’s Lisp
Y - Similar to Van Rossum’s Python
Features of C language


Imperative/Declarative language
Multi-dimensional arrays, type casting
Pointers and Function pointers (FP)
Passing/returning FP, Passing/returning
array of FP, FP within FP
Sample C code



1.Clike - Factorial calculation
1.uXML - uXML equivalent
2.Clike - Function pointer
Features of P language

Imperative/Declarative language
Features similar to those of C except
pointers
Nested procedures and procedure
parameters
Non-local variable access using static
and dynamic scoping
Sample P code



1.Plike - Static vs. Dynamic scoping
1.uXML - uXML equivalent
2.Plike - Procedure parameters
Features of J language


Object oriented language
Class and constructor definitions
Inheritance and hierarchical constructor
calls
Object instantiation prior to usage
Sample J code



1.Jlike - Inheritance
1.uXML - uXML equivalent
2.Jlike - Constructor Calls
Features of L language


Functional language
Functions as first-class objects
Operators are functions
defun / lambda functions
let, setq, map, reduce features
Sample L code


1.Llike - Reduce
1.uXML - uXML equivalent
2.Llike - Let
3.Llike - Defun
Features of Y language

Imperative/Dynamic language
No variable declaration required,
Dynamic typing
Multi-dimensional mix arrays
lambda function definition
map, reduce features
Sample Y code



1.Ylike - Map
1.uXML - uXML equivalent
2.Ylike - Mix Arrays, lambda
Features of Code Analysis tool

 Name/count of function, variable, class,
 constructor definitions
 Count of function/constructor calls
 Count of methods overridden
 McCabe Cyclomatic complexity
 Helstead Metrics, Maintainability index
Software Metrics
     Function defined : 1
void main()
____________________________________________
                                               function void main() { 
Function calls : 1                               int i = 2 * 2 + 2, j = 1;
main                                               do {
____________________________________________           i = i - 1;
Variables defined : 2
i : int                                                print("i=",i,(j+2));
j : int                                            }while(i);
____________________________________________       
Constants used: 8
int : 2                                            i = 5;
int : 2                                          }
int : 2
int : 1
int : 1
string : i=
int : 2
int : 5
____________________________________________
McCabe Cyclomatic Complexity : 3
____________________________________________
Classes defined : 0
____________________________________________
Functions overriden : 0
_____________________________________
Nested Block Depth : 1
Helstead Metrics

function void main() { 
  int i = 2 * 2 + 2, j = 1;
    do {
        i = i - 1;
        print("i=",i,(j+2));
    }while(i);
    
    i = 5;
  }

 
Helstead Metrics :
N1 = 9, n1 = 7, N2 = 16, n2 = 7
Program Length N => N1 + N2 = 25
Vocabulary Size n => n1 + n2 = 14
Program Volume V => N * log2(n) = 95.18387305144009
Difficulty Level D => (n1 / 2) * (N2 / n2) = 8.0
Program Level L => 1/D = 0.125
Effort to implement E => V*D = 761.4709844115207
Time to implement T = E/18 = 42.303943578417815
No. of bugs delivered B => E^(2/3)/3000 = 3.333333333333333E-4
Extensibility of uXML

uXML schema - Add new programming
language feature
Front end compilers - Write a new
language
Software Metric tool - Add new metrics
to measure the software
Drawbacks


uXML code has larger code size
All / Advanced features of languages not
covered
Many programming paradigms not
included in uXML schema
Future Work

Update uXML schema to incorporate
different paradigms
Make uXML compiler more efficient
Robust programming language
converter tool
Source code as part of comments in
equivalent uXML code
Misc. details of uXML


Developed in Java
Used Eclipse, JavaCC and xv tools
Source code version control
Approximately 150 test programs written
Approximately 6 months of time
Summary

uXML schema represents OO,
procedural and functional paradigms
Room to add more programming
paradigms
Common representation helps develop
powerful code analysis tools
All features of PL can’t be covered
uXML mentors

Dr. James Heliotis
•   Idea of uXML
•   Programming language features
Dr. Axel Schreiner
•   xv tool
•   XML processing tools
References

XV, XPath, JavaCC
The dragon book - Compilers
UNCOL, Phoenix, MSIL
C, Pascal, CLOS, Java, Python,
Smalltalk, Scheme, Modula-2
λ, Types, Scope, Subprograms, Metrics
Questions or Suggestion?
Thank you!!

U Xml Defense presentation

  • 1.
    uXML An Experiment inCommon Representation of Different Programming Paradigms Kunal S. Pathak
  • 2.
    Outline History Extensibility Objective Drawbacks Applications Future Work Architecture Summary Tools Questions Examples Thank you
  • 3.
    History Before UNCOL After UNCOL Programming Programming Machines languages Machines languages 1 1 1 1 2 2 U 2 N 2 3 3 C : O : : : N L N M M
  • 4.
    Examples of UNCOL Sun’sJava framework GNU Compiler Collection Microsoft’s .NET and Phoenix framework
  • 5.
    Objective Different from thatof UNCOL Design an XML schema (uXML) to represent the semantics of different programming paradigms Test the uXML against various programming languages Develop tools that use uXML
  • 6.
    Applications Software Metric tool Educationaltool Plug-n-play Programming Language (specific paradigms) Source language converter tool Extract the program structure
  • 7.
    Architecture uXML format C Program <uXML language="abc" scope="static"> Interpreter Program (XV) output <function name="func"> P Program <returns type="void"/> <block> ... uXML ... Schema Valid- </block> J Program ation </function> ... ... L Program <call> <variable name=”func” / Software > Code Analysis Metrics </call> Y Program ... </uXML> Front end Back end
  • 8.
    Architecture cont. Compiler framework- Activation record, Symbol table, Display, Calling sequence, Datatypes Back end parser - uXML visitor Front end parsers - C, P, J, L and Y
  • 9.
    Tools in uXML Codeinterpreter - xv • Visit uXML nodes and execute the respective code Code analysis - xv, xsl • Count the appropriate uXML nodes
  • 10.
    Why XML inuXML? Program = Syntax tree = XML Human understandable Retains the semantics of the program Many XML processing tools - XSL, XSL-FO, XQuery, etc Universally accepted
  • 11.
    Few uXML elements <var/>,<variable/>, <constant/> <assign/>, <operator/>, <for-loop/>, <iterate/>, <cast/> <function/>, <class/>, <constructor/>, <block/>, <call/> ‘scope’ and ‘var-declaration’ attribute of <uXML/>
  • 12.
    PL features handledby uXML Iterations, if-else, arrays, pointers Function definition/call, nested procedures, functions as first-class objects Static vs. Dynamic Typing and Scoping Classes, Constructors, Inheritance
  • 13.
    Front end Parsers C- Similar to Dennis Ritchie’s C P - Similar to Niklaus Wirth’s Pascal J - Similar to Sun Microsystem’s Java L - Similar to John McCarthy’s Lisp Y - Similar to Van Rossum’s Python
  • 14.
    Features of Clanguage Imperative/Declarative language Multi-dimensional arrays, type casting Pointers and Function pointers (FP) Passing/returning FP, Passing/returning array of FP, FP within FP
  • 15.
    Sample C code 1.Clike- Factorial calculation 1.uXML - uXML equivalent 2.Clike - Function pointer
  • 16.
    Features of Planguage Imperative/Declarative language Features similar to those of C except pointers Nested procedures and procedure parameters Non-local variable access using static and dynamic scoping
  • 17.
    Sample P code 1.Plike- Static vs. Dynamic scoping 1.uXML - uXML equivalent 2.Plike - Procedure parameters
  • 18.
    Features of Jlanguage Object oriented language Class and constructor definitions Inheritance and hierarchical constructor calls Object instantiation prior to usage
  • 19.
    Sample J code 1.Jlike- Inheritance 1.uXML - uXML equivalent 2.Jlike - Constructor Calls
  • 20.
    Features of Llanguage Functional language Functions as first-class objects Operators are functions defun / lambda functions let, setq, map, reduce features
  • 21.
    Sample L code 1.Llike- Reduce 1.uXML - uXML equivalent 2.Llike - Let 3.Llike - Defun
  • 22.
    Features of Ylanguage Imperative/Dynamic language No variable declaration required, Dynamic typing Multi-dimensional mix arrays lambda function definition map, reduce features
  • 23.
    Sample Y code 1.Ylike- Map 1.uXML - uXML equivalent 2.Ylike - Mix Arrays, lambda
  • 24.
    Features of CodeAnalysis tool Name/count of function, variable, class, constructor definitions Count of function/constructor calls Count of methods overridden McCabe Cyclomatic complexity Helstead Metrics, Maintainability index
  • 25.
    Software Metrics Function defined : 1 void main() ____________________________________________ function void main() {  Function calls : 1   int i = 2 * 2 + 2, j = 1; main     do { ____________________________________________         i = i - 1; Variables defined : 2 i : int         print("i=",i,(j+2)); j : int     }while(i); ____________________________________________      Constants used: 8 int : 2     i = 5; int : 2 } int : 2 int : 1 int : 1 string : i= int : 2 int : 5 ____________________________________________ McCabe Cyclomatic Complexity : 3 ____________________________________________ Classes defined : 0 ____________________________________________ Functions overriden : 0 _____________________________________ Nested Block Depth : 1
  • 26.
    Helstead Metrics function voidmain() {    int i = 2 * 2 + 2, j = 1;     do {         i = i - 1;         print("i=",i,(j+2));     }while(i);          i = 5; }   Helstead Metrics : N1 = 9, n1 = 7, N2 = 16, n2 = 7 Program Length N => N1 + N2 = 25 Vocabulary Size n => n1 + n2 = 14 Program Volume V => N * log2(n) = 95.18387305144009 Difficulty Level D => (n1 / 2) * (N2 / n2) = 8.0 Program Level L => 1/D = 0.125 Effort to implement E => V*D = 761.4709844115207 Time to implement T = E/18 = 42.303943578417815 No. of bugs delivered B => E^(2/3)/3000 = 3.333333333333333E-4
  • 27.
    Extensibility of uXML uXMLschema - Add new programming language feature Front end compilers - Write a new language Software Metric tool - Add new metrics to measure the software
  • 28.
    Drawbacks uXML code haslarger code size All / Advanced features of languages not covered Many programming paradigms not included in uXML schema
  • 29.
    Future Work Update uXMLschema to incorporate different paradigms Make uXML compiler more efficient Robust programming language converter tool Source code as part of comments in equivalent uXML code
  • 30.
    Misc. details ofuXML Developed in Java Used Eclipse, JavaCC and xv tools Source code version control Approximately 150 test programs written Approximately 6 months of time
  • 31.
    Summary uXML schema representsOO, procedural and functional paradigms Room to add more programming paradigms Common representation helps develop powerful code analysis tools All features of PL can’t be covered
  • 32.
    uXML mentors Dr. JamesHeliotis • Idea of uXML • Programming language features Dr. Axel Schreiner • xv tool • XML processing tools
  • 33.
    References XV, XPath, JavaCC Thedragon book - Compilers UNCOL, Phoenix, MSIL C, Pascal, CLOS, Java, Python, Smalltalk, Scheme, Modula-2 λ, Types, Scope, Subprograms, Metrics
  • 34.
  • 35.

Editor's Notes

  • #2 Name, Started in Dec 2007, Masters in CS (Languages and Tools)
  • #3 I would like to tell the Applications of uXML first so that audiences understand what is the significance of uXML before understanding the core of it. Tools - developed the tools that uses uXML. Examples - uXML nodes, Extensibility - how you can add new components easily and extend uXML, Drawbacks - everything has drawbacks, Future Work - Things that I might think of adding in uXML, Summary, Q&amp;A THANK YOU
  • #4 1960 form intermediate between problem-oriented languages and machine language M*N to M+N Explain the advantage of having a UIL - compilers, machine, etc. Why UNCOL failed? - Ambitious, no advanced compilers, not enough memory, slow machines
  • #5 JVM - Bytecode is IL. Scala, JRuby, Jython, Groovy, Rhino. Small M, large N GNU - C, C++, Java converts to GENERIC, Small M, Large N .NET - CIL. VB, C#, F#, VC++, ASP. Large M, small N Phoenix - Framework for building compilers, CIL -&gt; IR, tools like memory tracing, code coverage, block counting, Large M, small N
  • #6 UNCOL - Already many tools Execution vs. Representation of semantics To prove - develop tools
  • #7 Explain these as applications of a universal intermediate language s/w metrics tool - A common tool that does the code analysis of programs written in different paradigm education tool - compile framework, programs can be compared by metrics language converter - ambitious idea program structure - Extract the structure of a program The idea is how quickly can you develop a tool that is handy for wide range of languages
  • #8 2 tools so far - Interpreter and Code Analysis IR is validated against the uXML schema
  • #9 Activation record - Enter the block, Leave the block, Symbol table - Add/remove symbol (datatype, mutable, name) Display - Data structure containing list of activation records to access the non-local variables Calling Sequence - Steps to be taken while calling/returing a function. Prototype for static/dynamic access Datatypes - Function, Int, Char, String, Overloaded function type 2 parts - Backend and Front end
  • #11 Programs are syntax trees. XML is also represented as trees Understandable - semantics are retain, no for loops in bytecode Processing tools - Extracting the data is easy, formatting, translating, thus many end users as oppose to MSIL or bytecode that has just 1 user and that is interpreter itself
  • #12 Definition of each node Explain &amp;#x2018;scope&amp;#x2019; and &amp;#x2018;var-declaration&amp;#x2019; attributes in brief
  • #13 Scoping - Context where values and expr are associated, how local variables are bound Static scoping - variable association at compile time Dynamic scoping - variable association at runtime
  • #15 All languages contain if-else, while, for so won&amp;#x2019;t mention explicitly
  • #19 Alike Java instantiation of object is needed before usage, else compiler throws error.
  • #20 1st parameter to the function/field is an object whose member is getting accessed. Parametric Polymorphism or Generics - Object as 1st parameter decides whose method to call
  • #21 Closures Why operators are function? Code metrics
  • #25 MCC - No. of linearly independent paths in the source code, control flow graph. Give eg. Helstead Metrics - Maintainability index - VS 2008 uses Helstead to calculate this factor.
  • #27 Operators : N1 = Total , n1 = distinct Operands : N2 = Total , n2 = distinct Analogy of a book - Difficulty - increases with repetitive operands Volume - How much information to be absorbed Effort - efforts to write the code Time - in secs and 18 is stroud number - humans detect 5 to 20 moments/discrete events /sec - not used much jeh pointed out, Compare the programs with respect to difficulty, efforts, etc.
  • #29 Advanced features - thread, read/write, file handling, interface, etc Missing programming paradigm - Logical, Aspect-oriented, Process oriented, etc.
  • #30 uXML compiler can be improved to make it execute faster Comments - Part of Y language
  • #34 There are lot of articles, however these points to some of the finest articles that helped me in developing the project.