看lua解释器源代码的时候发现和lua官网上给的有点出入,自己记录一下
官网的文档:https://www.lua.org/manual/5.3/manual.html,直接在页面搜索BNF就行了
以下是从源码的注释里扣出来的,源码注释有些地方写的有点问题,可能是作者版本迭代的时候忘记改注释了,帮作者改了一点
block -> statlist
statlist -> { stat [';'] }
fieldsel -> ['.' | ':'] NAME
index -> '[' expr ']'
constructor -> '{' [ field { sep field } [sep] ] '}'
sep -> ',' | ';'
field -> listfield | recfield
recfield -> (NAME | '['exp1']') = exp1
listfield -> exp
body -> '(' parlist ')' block END
parlist -> [ param { ',' param } ]
param -> NAME | '...'
explist -> expr { ',' expr }
funcargs -> '(' [ explist ] ')' | constructor | STRING
primaryexp -> NAME | '(' expr ')'
suffixedexp -> primaryexp { '.' fieldsel | '[' exp ']' | ':' NAME funcargs | funcargs }
simpleexp -> FLT | INT | STRING | NIL | TRUE | FALSE | ... | constructor | FUNCTION body | suffixedexp
subexpr -> (simpleexp | unop subexpr) { binop subexpr }
assignment -> ',' suffixedex

本文档记录了从lua 5.3解释器源代码中整理出的BNF,与官方文档存在一些出入。在阅读源代码过程中,注意到部分注释有误,已对错误进行修正。
328

被折叠的 条评论
为什么被折叠?



