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

Syntax

if                -- "if" keyword
  a == 4          -- an expression
then              -- "then" keyword
  print "Hello";  -- a statement

Our general pattern for an if statement is

"if"  <expression>   "then"  <statement>

Perl 6 gives us a handy way to express this pattern as a regex:

rule if_statement { if <expression> then <statement> }

Here, <expression> and <statement> refer us to other regexes that can parse individual expressions and statements.

Copyright © 2006 Patrick Michaud