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

Using the compiled parser subroutines from PIR

Once the grammar is compiled, we can include it into a Parrot program and use it for parsing:

.include 'simple.pir'

.sub 'foo'
  ...
  ##   get the parrot sub for parsing an expression
  parse = find_global 'Simple::Grammar', 'expression'

  ##   the expression to be parsed
  expr = '3 + 4 * (a-2)'

  ##   parse the expression
  match = parse(expr)

  ##   dump the parse tree
  '_dumper'(match)
Copyright © 2006 Patrick Michaud