我正在寻找Ruby BNF语法形式的内容。是否有官方版本?
YACC语法在Ruby源代码中。下载并运行捆绑的工具以获取可读的语法。
wget ftp://ftp.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p195.tar.gz
tar xvzf ruby-2.0.0-p195.tar.gz
cd ruby-2.0.0-p195
ruby sample/exyacc.rb < parse.y
输出样例(v2.0.0-p195版本共918行)
program : top_compstmt
;
top_compstmt : top_stmts opt_terms
;
top_stmts : none
| top_stmt
| top_stmts terms top_stmt
| error top_stmt
;
top_stmt : stmt
| keyword_BEGIN
'{' top_compstmt '}'
;
bodystmt : compstmt
opt_rescue
opt_else
opt_ensure
;
compstmt : stmts opt_terms
;
是的,布法罗大学提供了一份Ruby BNF语法。
编辑:我还找到了这份备选的Ruby BNF语法。
另外还有官方版本:Ruby草稿规范。你可以在那里找到语法。
Ruby草稿规范:http://ruby-std.netlab.jp。服务器已经关闭,但你可以从http://www.ipa.go.jp/osc/english/ruby下载。
git clone https://github.com/ruby/ruby ; cd ruby ; ruby sample/exyacc.rb < parse.y
即可。这将从 Github 克隆 Ruby 代码仓库,进入该仓库的目录,然后使用解析器文件 parse.y 运行 exyacc.rb 脚本。 - Lance