lua-users home
lua-l archive

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




2013/10/28 Peter M <lua4web@gmail.com>


28.10.2013 2: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.
>
> Thanks,
> Jason

I'm not a CS guru either, but my humble guess is that the var on the right hand side means any another string matching var definition, not the var on the left side.

An example: 'x.foo' is var on the left side, and on the right side it matches (another) var 'x' followed by a dot and Name 'foo'.

So there is nothing bad in the definitions being recursive.

Peter M


The left-recursion does hurt an LL parser. Lua parser actually uses another set of syntax rules, which eliminate left-crusion. I'm curious why Lua documents describes a different syntax than what is actually used in code. I guess the two are equivalent, but it is hard to mentally figure out.