Slash Boxes
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 ]

Ovid (2709)

  (email not shown publicly)
AOL IM: ovidperl (Add Buddy, Send Message)

Stuff with the Perl Foundation. A couple of patches in the Perl core. A few CPAN modules. That about sums it up.

Journal of Ovid (2709)

Thursday March 27, 2008
10:57 AM

The Parrot Compiler Toolkit Tutorial

[ #35989 ]

The tutorial for writing compilers in Parrot is rather interesting. After failing to build parrot on Solaris, destroying the master boot record on my Windows box (don't ask) and killing all network connectivity in VMWare Ubuntu (never, never hire me for any system administration work), I finally managed to get parrot compiled (the magic invocation on Ubuntu appears to be sudo apt-get install build-essential). What amazes me about all of this is that the BBC pays me for this sort of fun.

If you're working through the tutorial, you might find the following bash aliases useful (adjust paths to taste):

alias squaak="$HOME/code/parrot-0.6.0/parrot \
alias example="find $HOME/code/parrot-0.6.0/languages/ -name '*.pm'| \
  xargs grep "

The first one is obvious and the second one lets me quickly and easily search for example code that suits my needs.

Also, don't forget to rerun 'make' every time you change the grammar or actions. D'oh!

It's also worth noting that just because your code parses doesn't mean that it can be converted to PIR. Right now I'm trying to work out the cryptic Null PMC access in find_method() error (doesn't occur during the parse as my syntax is valid). The Parrot Compiler Toolkit is new and lots of fun, but plenty of rough edges, too.

Update: found the bug. The following two methods are not the same. Not a useful error message, though. It appears accurate and I'm sure it will get better with time.

# Mine:
method if_statement($/) {
    my $cond := $( $<expression> );
    my $then := $( $<block> );
    my $past :=
        $cond, $then,

    if $<else> {
        $past.push( $( $<else>[0] ) );
    make $past;

# Tutorial:
method if_statement($/) {
    my $cond := $( $<expression> );
    my $then := $( $<block> );
    my $past := $cond, $then,
                              :node($/) );
    if $<else> {
        $past.push( $( $<else>[0] ) );
    make $past;

See the bug?

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • /me hates case-errors
    • Same here. I eventually gave up and cut-n-pasted the code from the tutorial and things worked. Then it was a binary search through the code before I saw my problem.

      Then there's that little bit in the try/catch grammar rules which requires embedded pir, but the tutorial doesn't mention that when it suggests you implement it.