lua-users home
lua-l archive

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


On Jan 15, 2008 4:45 PM, Nicolai Mainiero <lists@mainiero.de> wrote:
> Hi,
>
> I'm writing a parser for lua and found some strange rules in the EBNF
> Syntax available athttp://www.lua.org/manual/5.1/manual.html#8
>
>
>
> exp ::=  nil | false | true | Number | String | `...´ | function |
>                  prefixexp | tableconstructor | exp binop exp | unop exp
>
> prefixexp ::= var | functioncall | `(´ exp `)´
>
> functioncall ::=  prefixexp args | prefixexp `:´ Name args
>
> args ::=  `(´ [explist] `)´ | tableconstructor | String
>
>
> Looking at these four rules above the Language allowes functioncalls
> like:
>
>
> ("Hello")"hello"
>
> or
>
> (nil):Test("hello")
>
>
> Which are obviously senseless and when I try to execute them the
> interpreter gives me the following error message:
>
> ambiguous syntax (function call x new statement) near '('
>
> Is this intenden behaviour or is this an error and somebody can provie
> me a updated EBNF syntax.
>
> Best regards,
>
> Nicolai Mainiero

It's problematic because the base types of Lua can have __index and
__call metamethods:

debug.setmetatable(nil, {__index = {Test = function(_,v)  print(v .. "
world");  end}})
debug.setmetatable('', {__call = function(_,v)  print(v .. " world");  end}})

...run these and your examples will work.