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

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>

As a BNF grammar, we might say

if_stmt ::=
    'if' expression 'then' statement

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

rule if_stmt { if <expression> then <statement> }
Copyright © 2007 Patrick Michaud