Parrot Compiler Tools Parrot Compiler Tools #23

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

transform past (ABC::Grammar::statement) :language('PIR') {
    .local pmc arg0node, arg1node
    #  get the two operands
    $P0 = node['term']
    arg0node = $P0[0]
    arg1node = $P0[1]
    #  get the ASTs of the two operands
    .local pmc arg0past, arg1past
    arg0past = tree.'get'('past', arg0node, 'ABC::Grammar::term')
    arg1past = tree.'get'('past', arg1node, 'ABC::Grammar::term')
    #  build the operation node
    .local pmc oppast
    oppast = new 'PAST::Op'
    oppast.'init'(arg0past, arg1past, 'node'=>node, 'pirop'=>'add')
    .return (oppast)
}
Copyright © 2007 Patrick Michaud