Perl 6 Compiler Design and Implementation of the Perl 6 Compiler #17

Grammars

The base class for rules is PGE::Rule.

A grammar is simply any class derived from PGE::Rule that contains rule methods.

Thus, one can create a new grammar with:

$P0 = getclass "PGE::Rule"
$P1 = subclass $P0, "MyGrammar"

$P2 = p6rule("<[$@%&]>")
store_global "MyGrammar", "sigil", $P2

$P2 = p6rule("<sigil> <ident>")
store_global "MyGrammar", "var", $P2

$P2 = p6rule("my <MyGrammar::var> = (\d+)")
# ...

PGE's built-in rules are all methods of PGE::Rule, although some will also provide built-in optimizations to avoid unneeded subroutine calls.

Copyright © 2005 Patrick R. Michaud