lua-users home
lua-l archive

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





2013/10/29 Patrick Donnelly <batrick@batbytes.com>

Hi Jason,

2013. 10. 27. 오후 6:06에 "Jason Nielsen" <drjdnielsen@gmail.com>님이 작성:


>
> I've been looking at the EBNF in the manual and I'm a bit confused by the following two rules:
>
> var ::=  Name | prefixexp ‘[’ exp ‘]’ | prefixexp ‘.’ Name
>
> prefixexp ::= var | functioncall | ‘(’ exp ‘)’
>
> if you expand this out you get var on the right hand side of the var rule definition.  I'm not a CS guru so perhaps I'm misunderstanding EBNF notation.

This is called left-recursion and is incompatible with lpeg in a straight port of the grammar. See [1] for a solution.

[1] http://lua-users.org/lists/lua-l/2010-12/msg00699.html

- Patrick


That's why I think it is annoying to document the BNF differing than the actual implementation. There is no such problem in the real parser, and there should be no need to invent another solution. The BNF in Lua parser is:

expr => subexpr
subexpr => (UNOP subexpr | simpleexp) (BIOP subexpr)*
simpleexp => NUMBER  |  STRING  |  NIL  |  TRUE  |  FASLE  |  DOTS  |
constructor   |
"function" body   |
suffixedexp
suffixedexp => primaryexp (fieldsel | yindex | (":" NAME funcargs) | funcargs)?
primaryexp => "(" expr ")" | NAME