Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

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
https://www.xing ... hard_Schmalhofer

A freelance software engineer with experience in webapplications, databases and bioinformatics.

A contributor to Parrot and the person behind Pipp.

A physicist who worked with third sound in Helium-III and CCD X-ray detectors.

barney on irc.perl.org
github: http://github.com/bschmalhofer [github.com]
LinkedIn:http://www.linkedin.com/in/bernhardschmalhofer [linkedin.com]
XING: https://www.xing.com/profile/Bernhard_Schmalhofer [xing.com]

Journal of Bernhard (4508)

Sunday January 06, 2008
01: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.