I'm looking for Ruby grammar in BNF form. Is there an official version?
The :: is a unary operator and is used to access (anywhere outside the class or module) constants, instance methods and class methods defined within a class or module. Note: In Ruby, classes and methods may be considered constants too.
Ruby interprets newline characters(\n) and semicolons(;) as the end of a statement. Note: If a line has +, – or backslash at the end of a line, then it indicates the continuation of a statement.
Ruby blocks are anonymous functions that are enclosed in a do-end statement or curly braces {} . Usually, they are enclosed in a do-end statement if the block spans through multiple lines and {} if it's a single line block.
EOS means end of string. it is displayed at the end of the string.
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 ;
Yes, there is one Ruby BNF syntax by the University of buffalo.
Edit: I've also found this alternate Ruby BNF syntax.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With