Ruby语法

use*_*109 40 ruby grammar bnf

我正在寻找BNF形式的Ruby语法.有正式版吗?

Ken*_*chi 29

YACC语法在Ruby源代码中.下载并运行捆绑的utiliy以获得可读的语法.

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
Run Code Online (Sandbox Code Playgroud)

输出样本(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
                ;
Run Code Online (Sandbox Code Playgroud)

  • 现在只是`git clone https://github.com/ruby/ruby; cd ruby​​; ruby sample/exyacc.rb <parse.y` (5认同)

Adr*_*ore 15

是的,水牛大学有一种Ruby BNF语法.

编辑:我也发现了这种备用Ruby BNF语法.

  • 但我不认为第一个链接是"官方"语法.我听说Ruby的官方语法最接近的是parse.y文件. (5认同)
  • 不幸的是,类似的UoB和njit语法是完全错误的.for循环中没有do,extend和include语句丢失,缺少异常变量. (5认同)

Gut*_*nYe 5

也是正式版:Ruby Draft Specification.你可以在那里找到语法.

Ruby草案规范:http://ruby-std.netlab.jp.服务器已关闭,但您可以从http://www.ipa.go.jp/osc/english/ruby下载它