Parrot Compiler Tools Running Your Programming Language on Parrot #24

An ast grammar for our "abc example" (ROOT node)

transform past (ROOT) :language('PIR') {
    .local pmc stmtnode, stmtpast
    # get the AST for our statement
    stmtnode = node['statement']
    stmtpast = tree.'get'('past', stmtnode, 
                          'ABC::Grammar::statement')
    # print the statement's results
    .local pmc printpast
    printpast = new 'PAST::Op'
    printpast.'init'(stmtpast, 'node'=>node, 'pirop'=>'say')
    .local pmc blockpast
    blockpast = new 'PAST::Block'
    blockpast.'init'(printpast)
    .return (blockpast)
}
Copyright © 2007 chromatic and Patrick Michaud