Ruby Grammar

[亡魂溺海] 提交于 2019-12-17 10:21:43

问题


I'm looking for Ruby grammar in BNF form. Is there an official version?


回答1:


Yes, there is one Ruby BNF syntax by the University of buffalo.

Edit: I've also found this alternate Ruby BNF syntax.




回答2:


The YACC syntax is in the Ruby source. Download it and run the bundled utiliy to get the readable syntax.

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

Output sample (total 918 lines for the v2.0.0-p195)

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
                ;



回答3:


also an official version: Ruby Draft Specification. you can find the grammar there.

Ruby Draft Specification: http://ruby-std.netlab.jp. the server is down, but you can download it from http://www.ipa.go.jp/osc/english/ruby



来源:https://stackoverflow.com/questions/663027/ruby-grammar

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!