Parrot/PGE, parsers Parsers, Perl 6 Rules, and the Parrot Grammar Engine #20

Creating a custom parse subroutine in PIR

In PIR, a subrule preamble might look like:

.sub "subrule"
    .param pmc mob         # incoming match state          
    .param pmc adverbs     :named :slurpy
    .local pmc match       # match object to return
    .local string target   # current match target
    .local int cpos        # current match position
    (match, cpos, target) = mob.'new'(adverbs :flat :named)

The last line initializes a new match object for the subrule to return to the caller, and also provides the current match position and target string.

Copyright © 2006 Patrick Michaud