简体   繁体   中英

why the sexp has array in the end

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

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".

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM