[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: lpeg could infer the validity of this grammar.
- From: Sean Conner <sean@...>
- Date: Mon, 15 Dec 2014 01:56:21 -0500
It was thus said that the Great Sam Putman once stated:
> On Sun, Dec 14, 2014 at 12:56 PM, Dirk Laurie <dirk.laurie@gmail.com> wrote:
> >
> > 2014-12-14 21:39 GMT+02:00 Sam Putman <atmanistan@gmail.com>:
> >
> > > expr = token + ( V"group" + V"factor" + V"term")
> > -- semicolon needed here
> > > group = P"(" * V"expr"^0 * P")";
> > > factor = #token * V"expr" * (P"*" + P"/") * V"expr";
> >
> > > This program fails with "rule 'expr' may be left recursive".
> >
> > If `expr` is not `token` or `group`, it tries `factor`.
> > The rule for `factor` invokes V"expr" before any
> > input has been consumed.
> >
>
> Hi Dirk,
>
> I do understand the cause for the failure to infer. The grammar is valid,
> but not valid lpeg, as lpeg stands.
LPeg is a Lua implementation of Parsing Expresson Grammars, which are
*NOT* (I repeat, *NOT*) the same as LR() or LL() parsers. There's a bit
more information about this on the Wikipedia:
http://en.wikipedia.org/wiki/Parsing_expression_grammar#Indirect_left_recursion
-spc