lua-users home
lua-l archive

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


>�would require a lookahead parser

Would it?

Let's say I am parsing the following and can only look at one letter at a time in order:
"local success ="

Let's say I'm in the middle of the word success. My current state is 'wait for whitespace or = '.�When I reach the '=' character, I know that the new variable name is going to be "success".

Now let's say I am parsing the following:
"local success(items, total)"

When I am in the middle of success and reach the '(' character, instead of throwing an error I know the new variable name is "success" and to go to the parse arguments state.

Granted, I am not aware of the internals of the Lua parser but this does not seem to require a lookahead parser.


On Wed, Jul 6, 2011 at 2:21 PM, Sebastien Lai <237482@googlemail.com> wrote:
On Wed, Jul 6, 2011 at 9:09 PM, David Hollander <dhllndr@gmail.com> wrote:
> Since the local scope does not have table semantics where it is indexable by
> an evaluation:
> local [getname()] = 3
> why not disrequire the use of the 'function' keyword when 'local' is
> present?
> local function success(items, total)
> � reply(client, view.list(items, total))
> end
> local success(items, total)
> � reply(client, view.list(items, total))
> end
> It shouldn't break�compatibility�with anything. It's basically just the
> removal of additional implicit syntax.
> 'local' implies initialization\definition and bars evaluation. '()' only
> appears in function declarations outside of evaluations.
> When the two appear together there is only one possibility.

The reason is because your code would require a lookahead parser (that
is, a parser that is able to detect a function declaration _expression_
before any explicit declaration _expression_) - and since Lua tries to
be as small as possible, this would likely make the interpreter much
bigger. Apart from that, it looks like purely syntactic sugar...