Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 79 lines (56 sloc) 2.717 kb
1b6cbf6 @pmichaud First draft of a perl 6 parser in p6 rules and pir.
pmichaud authored
1 =head1 Perl 6 parser
2
3 This is a Perl 6 parser, an early version (no version numbers yet).
4
5 I know you're probably looking for the Perl 6 compiler, but this
6 isn't it, at least not yet. Eventually it probably will be, but
7 for the moment it's just the parser. As we finish up TGE
8 (compilers/tge) and code generation, then this will probably
9 be the Perl 6 compiler.
10
11 (If you're in a hurry to write Perl 6 programs, you might try
12 looking at PUGS -- http://www.pugscode.org. Or, help us build
13 the compiler here -- read on!)
14
15 However, even though this is not a complete compiler yet, you can
16 still see how Perl 6 programs are parsed, help us create test
17 cases, and extend/improve the grammar to cover more of Perl 6.
18 Here's how to do it:
19
20 =head2 Compiling
21
22 The Perl 6 parser lives in the perl6.pbc file. To create this
23 file, simply issue the command
24
25 $ make
26
27 This directory comes with F<p6shell.pir>, which is a simple parrot
28 script designed to exercise the parser, both on static input files
29 and interactively via command line input. To run the parser
30 on a perl 6 input file named "foo.p6" and display the resulting
31 parse tree:
32
33 $ parrot p6shell.pir foo.p6
34
35 To run the parser interactively, entering single-line statements
36 and displaying the parse tree for each:
37
38 $ parrot p6shell.pir
39
40 =head2 Files
41
42 The "top" file for the parser is F<perl6.pir> which is used to
43 create the F<perl6.pbc> file. It initializes the overall
44 parsing system and registers the parser as a Parrot "Perl6" compiler.
45
46 The other files needed for parsing are in the F<lib/> subdirectory.
47
48 The F<lib/grammar.g> file defines the "top-down" grammar used for
49 large Perl 6 program structures. It consists of rule statements
50 defined in Perl 6 rules syntax and is compiled using the
51 C<rulec.pir> "rules compiler" from PGE to produce a lib/grammar.pir
52 file with the PIR version of the rules. (For more information on
53 Perl 6 rules, see Synopsis 5 and the Parrot Grammar Engine in the
54 F<compilers/pge> directory.)
55
56 The F<lib/parse.pir> file defines the "bottom-up" parser
57 operators, as well as any special-purpose rules needed for
58 parsing Perl 6 that are better written directly in PIR instead
59 of using the top-down rules syntax or bottom-up operator
60 precedence parser.
61
62 The PIR files in F<lib/> are then included as part of compiling
63 F<perl6.pir> to produce F<perl6.pbc>. One can then parse Perl 6
64 source by doing:
65
66 $P0 = compreg "Perl6"
67 $S0 = "...perl 6 source code..."
68 $P1 = $P0($S0)
69 # $P1 holds the parse tree of the Perl 6 source code
70
71
72 =head1 AUTHOR
73
74 Patrick Michaud (pmichaud@pobox.com) is the author and maintainer.
75 Patches and suggestions should be sent to the Perl 6 compiler list
76 (perl6-compiler@perl.org).
77
78 =cut
Something went wrong with that request. Please try again.