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 November 28, 2004
10:17 AM

Parrot YAML ain't machine language

[ #22034 ]

In the last weeks I have used some off-work hours for looking into Abstract Syntax Tree for Parrot. It looks like this is one of the less civilised areas of Parrot, as documentation is somewhat scarce.

Leo Tötsch added support for AST when coding for the infamous Piethon bet. So far one can take a Python program and turn it into PAST, Parro abstract syntax tree As Simple Text.

bernhard@linux:~/devel/Parrot/parrot/languages/python> cat hello_10.py
print 10;
bernhard@linux:~/devel/Parrot/parrot/languages/python> ./ast2past.py hello_10.py > hello_10.past
bernhard@linux:~/devel/Parrot/parrot/languages/python> more hello_10.past

# generated by ast2past.py on Sun Nov 28 16:06:29 2004

Parrot_AST(
  version(Const('0.1'))
_options(
) # _options
Src_File("hello_10.py")
Py_Module(
  _()
  Stmts(
   Py_Print(
    Const(10)
   ) # Py_Print
   Py_Print_nl()
   Void(
    Const(None)
   ) # Void
  ) # Stmts
) # Py_Module
# end
) # Parrot_AST
bernhard@linux:~/devel/Parrot/parrot/languages/python> ../../parrot hello_10.past
10

I have been trying to make that functionality available as a Parrot registered compiler. After making some educated guesses, it looks like it might be working.

bernhard@linux:~/devel/Parrot/parrot> cat eval_9.imc
.sub main @MAIN
     .local pmc past_compiler
     past_compiler = compreg "PAST"
     .local string past_source
     past_source = 'Parrot_AST( Py_Module( Stmts( Py_Print( Const(9) ) ) ) )'
     .local pmc past_compiled_sub
     past_compiled_sub = compile past_compiler, past_source
     print "before\n"
     past_compiled_sub()
     print "after\n"
     end
.end

bernhard@linux:~/devel/Parrot/parrot> ./parrot eval_9.imc
before
9after
bernhard@linux:~/devel/Parrot/parrot>

I still need to check wether the python tests are still working. If so I could add and some AST compiler tests.

The idea of Abstract Syntax Trees is mostly that the representation, that is the programming language, doesn't matter much. So it should't be hard to add support for any other tree format. For example one could use YAML. This might bring future support for Parrot YAML, which is an acronym for "Parrot YAML Ain't Machine Language".

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.