in reply to Re: Perl 6 rules and complexity
in thread Perl 6 rules and complexity

Yeah, it depends on the grammar but worst case is exponential (according to this guy anyway). If it's memoizable it's guaranteed to be linear in the length of the string being parsed (worst case is @rules * length($string) ). This only includes a very limited type of backtracking, once you allow more powerful regex-like backtracking on quantified rules it becomes very easy to lose linearity even with memoization.

It would be unfortunate if people could write programs that didn't either compile or fail in a reasonable time or if people took 2 pieces of code that independently compiled quickly but when appended compiled much more slowly.

The ability to cause arbitrary side-effects in rule actions makes that far easier to do or possibly even guarantees it for anything but the simplest grammars (for example any grammar that is an extension of Perl6's).

Replies are listed 'Best First'.
Re^3: Perl 6 rules and complexity
by zby (Vicar) on Feb 18, 2006 at 09:42 UTC
    To put that in context - it is known that type inference in languages like ML is DEXP Time complete (http://portal.acm.org/citation.cfm?coll=GUIDE&dl=GUIDE&id=96748, my Masters Thesis was a modified proof of that :))

      That might be in context but it's not a context that I'm the least bit familiar with!

      DTIME and DEXPTIME don't seem to have a lot of material about them on the web or at least they don't seem to have many introductions to the terminology. wikipedia and some lecture notes are the closest I could find.

      Apart from being a performance guarantee for a specific model of computation, rather than an asymptotic guarantee, how is DEXPTIME different from O(2^n)? Is it any worse or better. Is it just more precise or am I wrong to interpret DEXPTIME as DTIME(some exponential function)?

        DEXPTIME is Deterministic Expotential Time ie it is the same as O(2^n) for time (time is the most frequently used measure of complexity but there are others and among them is space). So I really should have written that ML grammar is expotential in the worst case too.