[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: functioncall vs varlist ambiguity
- From: Roberto Ierusalimschy <roberto@...>
- Date: Sat, 24 Jul 2010 18:30:09 -0300
> 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.
When the parser starts reading something like "a.f[x].g[i][k].f" it
cannot know whether this is a function call or an assignment, no
matter how much look-ahead it uses.
> Is there a clever trick to deal with this?
Use a bottom-up parser ;) They are much more powerful than LL parsers.
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.
-- Roberto