cardinal-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Cardinal-dev] There Is No Wheel


From: David Robins
Subject: Re: [Cardinal-dev] There Is No Wheel
Date: Wed, 20 Nov 2002 19:33:18 -0500 (EST)

On Wed, 20 Nov 2002, Phil Tomson wrote:

> On Wed, 20 Nov 2002, Sean Chittenden wrote:
[snip]
> > http://www.pragmaticprogrammer.com/ruby/downloads/files/nodeDump-0.1.7.tgz
> >
>
> nodeDump prints out a representation of the internal parsetree for a Ruby
> program, but as far as I can tell, it doesn't return an AST that can be
> walked from within Ruby.

I didn't like ruth's inspect method much for showing a tree, but I played
around with adding a 'show' method to TreeNode, and formatting things a bit
nicer.  The ruth parser is the best so far; the parrot/languages/ruby one
choked on '$0', for example (yep, I wrote a ruby script that parsed itself).

The tree's tolerable (I don't like some of the nodes, e.g. NODE_NEWLINE is
completely pointless, and NODE_ARRAY appears far too often, and others like
NODE_FCALL/NODE_VCALL could be folded into NODE_CALL with nil values for
receiver/args).  As I get time I'm going to start playing with some
IMCC-outputting methods, like eval() which would be a bit like ruby's own
eval.c but for each node, returns code to produce the result and the result
itself (which may be a constant, IMCC temporary register, or IMCC local).
e.g., the add operator would have something like:

def eval()
  lhsResult = lhs.eval
  rhsResult = rhs.eval
  return Result.new(code => lhsResult.code + rhsResult.code +
   "\tadd " + lhsResult.reg + ", " + rhsResult.reg, reg => lhsResult.reg)
end

Much oversimplified, of course.  I'll post code when/as I have it.  Not
everything will have an eval method, some of the rest will have to be
traversed differently.  (I must say I like ruby exceptions, makes the above
a lot simpler without having to check for nil/NULL/undef....)

Dave
Isa. 40:31





reply via email to

[Prev in Thread] Current Thread [Next in Thread]