|
Perl 6
viv: Revision 6
The 'viv' parser is a generated program for experimenting with the evolving Perl 6 language specifications, using only Perl 5 based software. The main source code of 'viv' is STD.pm, the "official" Perl 6 grammar, self referentially written in a subset of Perl 6. STD.pm parses Perl 6 source code, checking it for correct syntax and semantics, and converts it to a 'viv' abstract syntax tree (VAST). The chicken-or-egg bootstrap problem is how to use STD.pm on a computer that does not have a Perl 6 to run it. None of the current (March 2010) Perl 6 implementations (Rakudo, Pugs etc) can handle STD.pm, because amongst other things it uses Longest Token Matching (LTM), a feature of Perl 6 grammars that is particularly difficult to implement in a general purpose parser. A utility called 'gimme5' http://svn.pugscode.org/pugs/src/perl6/gimme5 comes to the rescue. Larry wrote 'gimme5' in Perl 5 to translate a subset of Perl 6 grammars into Perl 5 language. The STD.pm 'make' command uses 'gimme5' to translate STD.pm into 'viv'. Larry ensures that STD.pm is written in just a translatable subset of Perl 6, so that 'gimme5' can handle it. He also causes 'viv' to emulate Longest Token Matching, by carefully arranging the sequence of tokens where they occur as alternatives in STD.pm. The result is that longer tokens occur and match before shorter ones. Anyone can try 'viv' online. Join the #perl6 channel on irc.freenode.net, then address your command to the std: nick. For example: std: say "hello"; The output is either an awesome error message, or the status 'ok' followed by the amount of time and megabytes of memory that 'viv' took to parse the source. Unfortunately, 'viv' is not equipped to execute the code. Other language tools such as Mildew extend 'viv' further and may be able to do that. |