42

BNF形式のRuby文法を探しています。公式版はありますか?

4

3 に答える 3

35

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
                ;
于 2013-05-18T21:49:38.040 に答える
15

はい、バッファロー大学によるRubyBNF構文が1つあります。

編集:私はこの代替のRubyBNF構文も見つけました。

于 2009-03-19T16:55:05.397 に答える
5

また、公式バージョン: Ruby Draft Specification. そこで文法を見つけることができます。

Ruby ドラフト仕様: http://ruby-std.netlab.jp . サーバーがダウンしていますが、 http://www.ipa.go.jp/osc/english/rubyからダウンロードできます 。

于 2011-07-07T04:29:18.320 に答える