lua-users home
lua-l archive

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


* Roberto Ierusalimschy:

>> I'm writing yet another parser for Lua (more background soon,
>> hopefully) and I'm finally struggling with the ambiguity between
>> varlists (in assignments) and functioncalls.  If I'm not mistaken,
>> this ambiguity ensures that Lua is not LL(k) for any k.
>
> I think this ambiguity has nothing to do with varlists or Lua in
> particular.  It happens to any language that allows a minimum of
> flexibility in what is a variable and that allows variables to refer to
> functions.

And hasn't got assignments as expressions.

>> Is there a clever trick to deal with this?
>
> Use a bottom-up parser ;) They are much more powerful than LL
> parsers.

Yeah, but I started without a parser generator because I did not want
to depend on all-too-recent Emacsen.

> Or use the (dirty) trick that the Lua parser uses. Twist the
> grammar to something more or less like this:
>
>   callOrAssig = prefixexp rest
>   rest = "," restassign | "=" restassign1 | "(" etc.
>
> Things like "f(x) = 3" must be rejected outside the parser.

Yes, I went that route, too.  I think I've got a reasonably close
approximation, but it took a while and bit of fixing to get there.