Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

EBNF for Ruby?

2 views
Skip to first unread message

Sam Kong

unread,
Oct 13, 2006, 11:17:48 AM10/13/06
to
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

--
Posted via http://www.ruby-forum.com/.

Logan Capaldo

unread,
Oct 14, 2006, 2:50:23 PM10/14/06
to
On Sat, Oct 14, 2006 at 12:17:48AM +0900, Sam Kong 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.

Tomasz Wegrzanowski

unread,
Oct 14, 2006, 8:32:27 PM10/14/06
to
On 10/13/06, Sam Kong <sam.s...@gmail.com> 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] 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

--
Tomasz Wegrzanowski [ http://t-a-w.blogspot.com/ ]

Tom Copeland

unread,
Oct 14, 2006, 10:27:53 PM10/14/06
to
On Sun, 2006-10-15 at 09:32 +0900, Tomasz Wegrzanowski 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

Yours,

tom

0 new messages