lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]




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.

I'm not looking for help rewriting grammars, I can get around this particular hitch. 

Because factor calls #token, you and I know that the next call to token will succeed, if it is reached. So the call to expr, which calls token first, will succeed. So we can infer statically that it's safe to call factor. No loop will in fact occur.

#token fails with an illegal character or end of string, so factor will not call expr in that case.