tags:

views:

28

answers:

2
RubyParser.new.parse "1+1" 
s(:call, s(:lit, 1), :+, s(:array, s(:lit, 1))) 

Above code is from this link

Why there is array after + in the Sexp. I am just trying to learn ruby parser and the whole AST thing. I have been programming for a while but have no formal education in computer science. So do point to good article which explains AST etc. Please no dragon book. I tried couple of times but couldn't understand much of that book

+1  A: 

Just a guess: the array represents the parameter list. The "+" message is sent to the first "1" with a list of parameters, which has only one item, the second "1".

Leventix
+1  A: 

In Ruby (or at least in MRI), all message sends have exactly one argument: an array. If you send a message with no arguments, the array will simply be empty, if you send a message with one argument (as is the case in this example), the array will have one element.

Jörg W Mittag
thanks for the answer. Did this behavior change in ruby 1.9? I will try this in rubinius to see what behavior is shown there.
Nadal