>>>>> "Simon" == Simon Cozens <[EMAIL PROTECTED]> writes:

Simon> [EMAIL PROTECTED] (Damian Conway) writes:

Damian> But in Perl 6, the consistency between a method's parameter
Damian> list and its argument list *is* checked at run-time, so
Damian> passing the wrong number of arguments is (quite literally)
Damian> fatal.

Simon> But wait! If we can check how many parameters to pass, we know
Simon> how many parameters to pass; problem solved. Sure, the parser
Simon> has to stay in a superposition of states until the check is
Simon> made, but we're close to requiring quantum supercomputers to
Simon> run this thing anyway.

Simon> I'm afraid I can't tell whether or not I'm being serious any
Simon> more.

I don't know if this has been discussed before, but there are
completely serious parsing algorithms that work this way, "forking"
into conceptually separate parsers that parse the input in parallel
before either vanishing or collapsing back together. The best known of
these is the Generalized LR algorithm (GLR), in which the individual
parsers can be like the well-known yacc/bison LALR(1) parsers, except
they split whenever there's a conflict in the parse table.

When the input has relatively few ambiguities, GLR parsers can be
competitive with LALR(1) ones in performance, and if they're
implemented right, their worst-case performance can also be tractable.
(Cubic in the input length, which is essentially tight for general
context free grammars. This holds even when there are exponentially
many possible parses, though obviously you only get an implicit
representation of them). GLR parsing was originally designed for
natural language parsing, but there's been research in the last few
years on using it for programming languages[*], and support for it was
recently added to Bison.

The snag I can see with using GLR parsing for Perl 6 is that it's
based on a model where you preprocess the grammar once at compile time
into a big fixed table, while Perl 6 would like to have a grammar that
can easily be changed on the fly.

[*] Disclaimer: some of which I was involved in.

A useful link:

http://www.cs.berkeley.edu/~smcpeak/elkhound/

 -- Stephen

Reply via email to