[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: getting rid of left-recursion in the Lua BNF
- From: Patrick Donnelly <batrick@...>
- Date: Wed, 15 Dec 2010 16:39:12 -0500
A while ago I wrote a Lua parser in lpeg [1]. I figure I should share
this "solution" to the left-recursion problem (namely prefixexp) in
the Lua's official syntax [2]. It's mainly useful for writing an lpeg
parser for Lua and preserving sanity when reading the BNF syntax (IMHO
of course):
(only posting changes/additions:)
value ::= nil | false | true | Number | String | '...' | function |
tableconstructor | functioncall | var | '(' exp ')'
exp ::= unop exp | value [binop exp]
prefix ::= '(' exp ')' | Name
index ::= '[' exp ']' | '.' Name
call ::= args | ':' Name args
suffix ::= call | index
var ::= prefix {suffix} index | Name
functioncall ::= prefix {suffix} call
Maybe the Lua authors would like to incorporate something similar.
Otherwise, I'm certain someone in the future will find this helpful;
after all, who doesn't think of making a Lua parser after looking at
lpeg? :)
[1] http://lua-users.org/wiki/LpegRecipes (See Lua Parser)
[2] http://www.lua.org/manual/5.1/manual.html#8
--
- Patrick Donnelly