[Rubygrammar-grammarians] Ruby Grammar Project

Terence Parr parrt at cs.usfca.edu
Sat Nov 26 14:54:03 EST 2005


On Nov 25, 2005, at 6:36 PM, Mauricio Fernandez wrote:
> IIRC they result in
>
>>  def foo
>     zort = 3 # assign to variable
>       => NODE_LASGN(ID:zort, INT2FIX(3), ...)
>>    blah = zort # assign to variable from variable
>       => NODE_LASGN(ID:blah, NODE_LVAR(zort), ...)
>>  end

That makes perfect sense.

>>  def foo
>>    blah = zort # assign to variable from method result
>      => NODE_LASGN(ID:blah, NODE_VCALL(0,ID:zort,0), ...)
>>    zort = 3 # assign to variable
>      => NODE_LASGN(ID:zort, INT2FIX(3), ...)
>>    ...
>>  end

Ah.  So the AST construction treats referenced values as method  
calls?  Interesting.  So the AST construction routine has to have  
flow analysis to see if something is defined on the path of that  
execution?  That doesn't sound like a very easy approach.  Imagine

if ...
	zort=3
end
blah = zort

In this case, which tree do you generate?  The flow analysis is the  
only thing that can answer that...something usually WAY further down  
the compilation pipe.

Well, I'm going to build a grammar.  If people want to use it for  
doing Ruby tools like refactoring engines, cool.  If people need it  
to replace the front-end of the Ruby interpreter, seems like there is  
much more involved than just a grammar with AST construction.   
'course you'd start with a grammar and add actions...

Ter


More information about the Rubygrammar-grammarians mailing list