Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Precedence of **

Reply
Thread Tools

Precedence of **

 
 
Caleb Clausen
Guest
Posts: n/a
 
      09-25-2007
I recently discovered that the precedence of ** seems to be at
variance with the documentation. All tables of precedence for Ruby
that I have found (including in the pickaxe) have listed ** as just
above that of the four unary operators + - ! and ~. However, ruby
actually parses 3 of these as higher precedence than **. This is most
obvious when using ParseTree:

$ irb -rubygems
irb(main):001:0> require 'parse_tree'
WARNING: overridding bool on
/usr/lib/ruby/gems/1.8/gems/ParseTree-2.0.2/lib/parse_tree.rb:244
=> true
irb(main):002:0> ParseTree.translate '!i**2'
=> [:call, [:not, [:vcall, :i]], :**, [:array, [:lit, 2]]]
irb(main):003:0> ParseTree.translate '~i**2'
=> [:call, [:call, [:vcall, :i], :~], :**, [:array, [:lit, 2]]]
irb(main):004:0> ParseTree.translate '+i**2'
=> [:call, [:call, [:vcall, :i], :+@], :**, [:array, [:lit, 2]]]
irb(main):005:0> ParseTree.translate '-i**2'
=> [:call, [:call, [:vcall, :i], :**, [:array, [:lit, 2]]], :-@]

Unary minus actually comes out as lower precedence than **, but the
other three unary ops all bind more tightly. I have seen this using
1.8.2 on Debian, and 1.8.5 and 1.8.6 on Ubuntu.

I see now that the table of precedence in parse.y actually has +, ~,
and ! as lower precedence than **. I thought it was going to be
something less obvious... Was it intended to be this way, and the
documentation is wrong?

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Does the Cisco VPN client map the IP Precedence from the IP headers? zher Cisco 1 07-19-2005 11:00 PM
route-map precedence ? raptor Cisco 4 06-10-2005 06:41 AM
prefix-list, as-path, route-map precedence ? raptor Cisco 0 03-25-2005 10:16 AM
Operator precedence David Frauzel Perl 2 05-16-2004 11:19 PM
time access lists with setting precedence Ivan Ostres Cisco 2 10-16-2003 07:00 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57