我正在尝试使用BNF表示法。我在https://www.lua.org/manual/5.3/manual.html#9看到了Lua5.3的完整语法。我想将do
和then
替换为{
,将end
替换为}
:
stat ::= ‘;’ |
varlist ‘=’ explist |
functioncall |
label |
break |
goto Name |
do block end | -> { block }
while exp do block end | -> while exp { block }
repeat block until exp |
if exp then block {elseif exp then block} [else block] end | -> if exp { block .... }
for Name ‘=’ exp ‘,’ exp [‘,’ exp] do block end | -> for ........ { block }
for namelist in explist do block end | -> for ........ { block }
function funcname funcbody |
local function Name funcbody |
local namelist [‘=’ explist]
funcbody ::= ‘(’ [parlist] ‘)’ block end -> ........... { block }
如何继续使用上面修改的语法来创建解释器?这可以吗?谢谢你的帮助。
答案 0 :(得分:0)
Replacing then
with {
and end
with }
conflicts with table constructors:
if a then print(1) end
becomes
if a { print(1) }
Conversely,
a = {}
becomes
a = then end