Stories
Slash Boxes
Comments

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Bernhard (4508)

Bernhard
  Bernhard.Schmalhofer@gmx.de

A physicist playing with bioinformatics and Parrot. Working as a freelance software engineer. Ohlo: http://www.ohloh.net/accounts/8606

Journal of Bernhard (4508)

Sunday January 06, 2008
02:30 PM

Parrot Abstract Syntax Tree in Scheme-XML

[ #35308 ]

As I'm hacking away at Eclectus, Scheme on Parrot in Scheme, I'm starting to pick some Scheme knowledge. So before implementing new features I employed my new wisdom and did some refactoring on my Scheme code.

The most nasty thing in compiler.scm was the generation of PIR while traversing the to-be-compiled s-expression. I decided to use XML Infoset as an intermediate representation, as I already have an XSLT sheet for generating a PIR representation of PAST from an XML representation of PAST. The nice thing is that the XML infoset can also be represented as a Scheme s-expression, that is SXML. The Scheme librarx SSAX-SXML can turn SXML into XML and perform XSLT operations.

For an example let's look at the Scheme form:

(fx+ (fx+ -10 11) (fx+ (fx+ 4 3) (fx+ 3 3)))

In Perl 5 this could be expressed:

say ( (-11 10) + ( (4 + 3) + (3 + 3)));

Represented as SXML this becomes: (|PAST::Stmts| (|PAST::Op| (|@| (pasttype "call") (name "say")) (|PAST::Op| (|@| (pirop "n_add")) (|PAST::Op| (|@| (pirop "n_add")) (|PAST::Val| (|@| (value -10) (returns "EclectusFixnum"))) (|PAST::Val| (|@| (value 11) (returns "EclectusFixnum")))) (|PAST::Op| (|@| (pirop "n_add")) (|PAST::Op| (|@| (pirop "n_add")) (|PAST::Val| (|@| (value 4) (returns "EclectusFixnum"))) (|PAST::Val| (|@| (value 3) (returns "EclectusFixnum")))) (|PAST::Op| (|@| (pirop "n_add")) (|PAST::Val| (|@| (value 3) (returns "EclectusFixnum"))) (|PAST::Val| (|@| (value 3) (returns "EclectusFixnum")))))))))

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.