From: Mathieu Bouchard Date: 2001-10-06T06:33:15+09:00 Subject: [ruby-talk:22144] Re: Ruby grammar ambiguities On Sat, 6 Oct 2001, Alan Stern wrote: > One of the least pleasing features of Ruby is the ambiguities of its > grammar. The most well-known example is the problem of distinguishing > whether a name (starting with a lower-case letter) represents a local > variable or a method call, but there are others. > Can any of the Ruby wizards out there provide us with a complete list > of these ambiguities, together with a description of the heuristics > that Ruby uses to decide each case? let me contribute a partial list: a & b # a.&(b) a& b # a.&(b) a&b # a.&(b) a &b # a(&b) also happens with +, -, * as a(+b), a(-b), a(*b). also happens with % as string-literal and / as regexp-literal a b, c d e, f, g # a(b,c(d(e,f,g))) in Ruby 1.6, forbidden in 1.7 a ? b : c # if a then b else c end (a)?(b):c # if a then b else c end a ? b: c # if a then b else c end a ? b:c # parse error a?b:c # a?(b(:c)) a ?b:c # parse error 1 ?b : c # if 1 then b else c end a ?b : c # parse error ... a?b # a?(b) a? b # a?(b) a ? b # parse error a ?b # a(?b) foo a, b, c, d # foo a, b, c, d foo a, b , c, d # foo a, b; parse error ________________________________________________________________ Mathieu Bouchard http://hostname.2y.net/~matju