Parrot and Perl 6 Parrot and Perl 6 - Environments for Dynamic Languages #32

Using the compiled parser subroutines from PIR

Once compiled, we can use the PIR in a Parrot program for parsing:

.include 'Simple.pir'
## ...

  ## get the expression to be parsed
  print "Enter expression to parse\n"
  expr = readline stdin

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

  ## parse the expression
  match = parse(expr, 'grammar'=>'Simple::Grammar')

  ## dump parse tree to stdout
  '_dumper'(match, 'match', '  ')
Copyright © 2007 Patrick Michaud