lua-users home
lua-l archive

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


> The syntax for function definition is
> 
> 	function ::= function funcbody
> 	funcbody ::= `(´ [parlist] `)´ block end
> 
> you need to lookahead parse until the "end" to know that this is a
> funcbody.

actually, no. I must admit to not having read luas parser, but I reckon it uses (something close to) a predicting parser (LL(k)), thus if the parser encounters the function token, it knows what to expect next and fails if it does not find that. Only L(whatever)R parsers would need to read until the end token in order to recognize the function. In the original case, local somevar() blah end vs. local somevar, the parser needs to look at the token following somevar in order to determine what kind of declaration it needs to parse for somevar. So lookahead is necessary. One token lookahead is probably not a problem as that is needed for the if-then-else-end construct anyway, but this will not suffice to take care of the syntactic ambiguities that would be introduced by this, which have already been pointed out in another post.

Disclaimer: I am somewhat rusty with these grammar things...

Gunnar