5,660,782 members and growing! (150 online)
Email Password   helpLost your password?
Development Lifecycle » Design and Architecture » General     Intermediate

Porting Code Through XML

By daluu

Framework for porting code between different languauges and platforms through a standard XML schema
VBScript, Javascript, XML, Perl, C++, C, C#, VB, JScript .NET, XSLT, Windows, .NET, .NET 1.1, .NET 2.0, Mono, Visual Studio, OpenGL, DirectX, ADO, ADO.NET, ASP, ASP.NET, WinForms, WebForms, Design, CEO, Architect, Dev, QA

Posted: 14 Jul 2007
Updated: 14 Jul 2007
Views: 10,026
Bookmarked: 6 times
Announcements
Loading...



Search    
Advanced Search
Sitemap
10 votes for this Article.
Popularity: 1.70 Rating: 1.70 out of 5
7 votes, 70.0%
1
1 vote, 10.0%
2
2 votes, 20.0%
3
0 votes, 0.0%
4
0 votes, 0.0%
5
Note: This is an unedited contribution. If this article is inappropriate, needs attention or copies someone else's work without reference then please Report This Article

Introduction

This article aims to present a framework for porting source code from one language or platform to another, using XML as the intermediate format in the conversion process.

Background

The concept of this article came to my mind last weekend or so while I was thinking about some programming and design related things. I don't know about you, the reader, but I have ported some amount of code from one language to another for work and personal projects. In most cases, I either ported the code due to design/usability issues (something lacking in source language/platform) or to support a larger target audience (who use a particular language or platform, usually due to convenience or their skillset).

Porting code, depending on what you are porting it to, can be trivial or complex. But even in the trivial case, it can still be tedious and time consuming to do. And porting to more than one target language or platform will multiply that factor some more. This can be alleviated with some form of automation or tools that handle this.

I don't know if there is any good solutions for this out there, but this article describes one possible solution. Due to the complexity of this solution, no code or real examples are presented. This article only describes a theoretical solution that is yet to be implemented.

The framework for porting code

The process of porting source code consists of two steps:

  1. Port source code (of the source language/platform) to the defined XML schema.
  2. Translate the intermediate XML to target language/platform.

Therefore, the framework consists of three parts:

  1. Source language/platform code parser that converts the code to XML.
  2. An XML schema that defines things like general programming language constructs such as loops, branches, variables, etc.
  3. An XML parser that converts the XML generated by step 1 to target language/platform.

The XML schema, would be like a subset of XML, like SVG, XSL, etc., something to yet to be defined (and maybe even standardized).

Ideally, to make the conversion effort simple and standardized for users/developers, the following are suggested when using this framework:

  • Parser for source language/platform should be written in the source language or built on the source platform. This will make it easier for the user to tweak the parser, when needed.
  • Parser for target language/platform should be written in XSLT. Since the intermediate format is in XML, XSLT provides the easiest language and platform agnostic way of parsing it. Additionally, with a XSL stylesheet template, you can easily derive customized stylesheets for each target language/platform by replacing the placeholder sections with target code and adding/removing some XSLT code snippets as needed.

Ideally, if this framework did exist (with defined XML schema and pre-built parsers), I would like it to cover much of the general programming and scripting languages out there like C, C++, C#, Java, Javascript, Perl, PHP, Python, VBScript, Visual Basic, Visual Basic .NET, etc.

Though I think of using this framework mostly to port between different languages, I believe it is also possible to extend the framework to support porting between platforms like Windows and Linux/Unix as well as porting from x86 to embedded platforms, etc.

Disclaimer: No framework is perfect. I would not expect this framework to provide flawless conversion between languages or platforms, but it would at least simplify the porting of 50-75 percent of the code since most code is usually of the general programming construct type as mentioned earlier in the article. The parts that aren't well ported can then be custom ported as needed.

Theoretical example of framework in action

Assume you have the following code snippet in VBScript:

For i = 1 To 100
    WScript.Echo "Code ran " & i & " times."
Next 

Run the code through the source parser and you should get some XML like the following:

<loop type="for">
<condition><var id="i"/><compare type="lessthan"/>100</condition>
<output>Code ran <var id="i"/> times.</output>
</loop> 

Run the code through the target parser (for C++) and you should get something like the following:

for(int i = 1; i < 100; i++)
{
    cout << "Code ran " << i << " times." << endLine;
} 

Disclaimer: This isn't a perfect example, code-wise, but is given just to illustrate the idea. The XML in the example probably is not the optimal schema, I just came up with it real quick. A real schema would take time to design and fine-tune.

Intentions of the framework

The framework is intended to be a platform and language independent solution that only relied on XML and XSLT. The language/platform choice for source code parser and processing the XML with XSLT would be up to the user.

Conclusion

That is all, any questions or comments? I would really love to work on such a framework along with the code parsers but I don't have the time for this right now. So I thought I would post my idea out for others to see and try.

If someone does pick up work on such a framework, please inform me as I would like to assist with such a project.

If such a framework is already in progress or exists, again, please inform me. I may delete this article, or this article might just provide another alternative implementation to such a framework.

History

July 14th 2007 - Initial post of article.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

daluu


Practitioner of C#, .NET, C++, C, ASP, VBScript, Windows Scripting Host, JScript, Perl, Perlscript, ADO.

Interested in automation, systems & application integration, web services & applications, and mobile computing.
Occupation: Software Developer
Location: United States United States

Other popular Design and Architecture articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 12 of 12 (Total in Forum: 12) (Refresh)FirstPrevNext
GeneralPart of the reason for the CLR/MSIL...memberreinux20:17 15 Jul '07  
GeneralRe: Part of the reason for the CLR/MSIL...memberdaluu11:53 16 Jul '07  
GeneralRe: Part of the reason for the CLR/MSIL... [modified]memberreinux17:56 16 Jul '07  
GeneralRe: Part of the reason for the CLR/MSIL...memberdaluu8:27 17 Jul '07  
GeneralCode GenerationmemberByteGhost16:31 15 Jul '07  
GeneralRe: Code Generationmemberdaluu19:32 15 Jul '07  
GeneralRe: Code GenerationmemberByteGhost1:53 16 Jul '07  
GeneralA good idea but...memberCraig G. Wilson13:18 15 Jul '07  
GeneralRe: A good idea but...memberdaluu19:26 15 Jul '07  
GeneralRe: A good idea but...memberCraig G. Wilson3:30 16 Jul '07  
QuestionOn Error GoTomemberThomas Lykke Petersen23:58 14 Jul '07  
AnswerRe: On Error GoTomemberdaluu19:37 15 Jul '07  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 14 Jul 2007
Editor:
Copyright 2007 by daluu
Everything else Copyright © CodeProject, 1999-2008
Mail5 | Advertise on the Code Project