Ruby语法

时间:2009-03-19 16:53:35

标签: ruby grammar bnf

我正在寻找BNF形式的Ruby语法。是否有官方版本?

3 个答案:

答案 0 :(得分: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

输出样本(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
                ;

答案 1 :(得分:15)

是的,水牛大学有一个Ruby BNF syntax

编辑:我还发现了这个替代Ruby BNF syntax

答案 2 :(得分:5)

也是官方版本:Ruby Draft Specification。你可以在那里找到语法。

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