# EBNF for Ruby?

**URL:** <https://www.ruby-forum.com/t/ebnf-for-ruby/72019>\
**Category:** Ruby\
**Created:** [October 13, 2006, 5:17pm UTC](https://www.ruby-forum.com/t/ebnf-for-ruby/72019 "2006-10-13T17:17:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ssk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/82dd89/32.png) [@ssk](https://www.ruby-forum.com/u/ssk)\
**Post date:** [October 13, 2006, 5:17pm UTC](https://www.ruby-forum.com/t/ebnf-for-ruby/72019/1 "2006-10-13T17:17:45Z")

</div>

Hi,

I heard from somebody that Ruby cannot be completely expressed in EBNF.  
And he also said that there are some ad hoc cases.  
Is it true?

Sam

---

<div class="post-metadata">

**Author:** ![ssk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/82dd89/32.png) [@ssk](https://www.ruby-forum.com/u/ssk)\
**Post date:** [October 14, 2006, 8:50pm UTC](https://www.ruby-forum.com/t/ebnf-for-ruby/72019/2 "2006-10-14T20:50:43Z")

</div>

On Sat, Oct 14, 2006 at 12:17:48AM +0900, Sam K. wrote:

> Hi,
> 
> I heard from somebody that Ruby cannot be completely expressed in EBNF.  
> And he also said that there are some ad hoc cases.  
> Is it true?  
> Check out parse.y (the yacc grammar for ruby) and see for yourself.  
> However, yes there are ad-hoc cases, mostly invovlving parentheses that  
> probably can not be expressed as a CFG.

---

<div class="post-metadata">

**Author:** ![ssk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/82dd89/32.png) [@ssk](https://www.ruby-forum.com/u/ssk)\
**Post date:** [October 15, 2006, 2:33am UTC](https://www.ruby-forum.com/t/ebnf-for-ruby/72019/3 "2006-10-15T02:33:16Z")

</div>

On 10/13/06, Sam K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi,
> 
> I heard from somebody that Ruby cannot be completely expressed in EBNF.  
> And he also said that there are some ad hoc cases.  
> Is it true?

If you want to parse Ruby, your best bet is probably ParseTree 🙂 [1]  
[1] [zenspider projects | software projects | by ryan davis](http://www.zenspider.com/ZSS/Products/ParseTree/)

Examples of difficult cases:  
foo { } # calls foo with empty hash or with empty block ?

foo + # Newlines are ignored when the expression is “not complete”  
bar

---

<div class="post-metadata">

**Author:** ![ssk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/82dd89/32.png) [@ssk](https://www.ruby-forum.com/u/ssk)\
**Post date:** [October 15, 2006, 4:29am UTC](https://www.ruby-forum.com/t/ebnf-for-ruby/72019/4 "2006-10-15T04:29:23Z")

</div>

On Sun, 2006-10-15 at 09:32 +0900, Tomasz W. wrote:

> Examples of difficult cases:  
> foo { } # calls foo with empty hash or with empty block ?
> 
> foo + # Newlines are ignored when the expression is “not complete”  
> bar

There are also some interesting notes on lexing Ruby in Xue Yong Zhi’s  
blog:

[http://seclib.blogspot.com/2005/11/more-on-leftshift-and-heredoc.html](http://seclib.blogspot.com/2005/11/more-on-leftshift-and-heredoc.html)

Yours,

tom
