BNF vs EBNF vs ABNF: which to choose?

You have to think about EBNF and ABNF as extensions that help you just to be more concise and expressive while developing your grammars. For example think about an optional non-terminal symbol, in a BNF grammar you would define it by using intermediate symbols like: A ::= OPTIONAL OTHER OPTIONAL ::= opt_part | epsilon while … Read more

Ruby Grammar

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 … Read more

Can this language be described by a non-ambiguous BNF grammar?

It’s not always easy (or even possible) to demonstrate that a grammar is ambiguous, but if there is a short ambiguous sentence, then it can be found with brute-force enumeration, which is what I believe that tool does. And the output is revealing; the shortest ambiguous sentence is the empty string. So it remains only … Read more