On Tue, Oct 04, 2005 at 09:16:58PM -0700, Joshua Hoblitt via RT wrote:
> Guys,
> 
> What is the status of this bug?  Should this be a PGE todo item?
My opinion is that it's "not a bug" -- the normal behavior for
most programs with infinite recursive loops is that they
eventually explode.  The original set of rules were

    rule atom  { A }
    rule binary { <expr> \* <atom> }
    rule expr { <binary> }

which is analogous to writing something like

    sub atom { print "A"; }
    sub binary { expr(); print "*"; atom(); }
    sub expr { binary(); }

and most people would consider "explode" to be, well, if not correct,
at least not a bug in the language translator.

Pm


> > [pmichaud - Sat Jul 02 15:27:11 2005]:
> > 
> > On Thu, Jun 30, 2005 at 02:56:27PM -0400, Will Coleda wrote:
> > > Attempting to come up with a simplistic math grammar that has one
> > possible
> > > operand (A) and one possible operator (*) - so that things like A,
> > A*A, and
> > > A*A*A*A*A are all parsed. This simplistic example (thanks to
> > spinclad on
> > > #perl6) cause PGE to explode.
> > >
> > > $ cat ta.p6r
> > > grammar f;
> > > rule atom  { A }
> > > rule binary { <expr> \* <atom> }
> > > rule expr { <binary> }
> > > $ ./parrot compilers/pge/demo.pir
> > 
> > Well.... yes, of course, since there's a left-recursive rule there
> > it's
> > very likely to explode.  (f::expr calls <binary>, which calls <expr>,
> > which calls <binary>, which calls <expr>, which calls <binary>, which
> > ... )
> > It's basically the same as what one would get from doing
> > 
> >     sub binary { expr(); atom(); }
> >     sub expr { binary(); }
> > 
> > and I'm not sure PGE should be responsible -- at least not yet --
> > for trapping such infinite loops.
> > 
> > If you rewrite the grammar to be right-recursive I think you'll
> > find it works fine:
> > 
> >     grammar f;
> >     rule atom { A }
> >     rule binary { <atom> \* <expr> }
> >     rule expr { <binary> }
> > 
> > > Also, $ ./parrot compilers/pge/demo.pir
> > > ...
> > > input "rule <pattern>", "glob <pattern>", "save <name>",
> > > target string, "pir", "exp", "trace", "next", or "use <file>"
> > > rule <f::expr>
> > >
> > > input "rule <pattern>", "glob <pattern>", "save <name>",
> > > target string, "pir", "exp", "trace", "next", or "use <file>"
> > > A
> > 
> > Well, "A" isn't a valid match for f::expr in the grammar you've
> > provided -- the f::expr rule calls <binary>, which absolutely
> > requires at least one \* .  If you want to match "A", "A*A", "A*A*A",
> > etc., I suggest:
> > 
> >     grammar f;
> >     rule atom { A }
> >     rule binary { <atom> [ \* <atom> ]? }
> >     rule expr { <binary> }
> > 
> > which eliminates the recursion altogether as well as recognizing a
> > single <atom> as a valid expression.
> > 
> > Pm
> > 
> > 
> 
> 

Reply via email to