compare 2 Asts

Andreas Pakulat apaku at gmx.de
Thu Jan 24 22:32:37 UTC 2008


On 25.01.08 00:15:28, Alexander Dymo wrote:
> On Thursday 24 January 2008 23:47:00 Andreas Pakulat wrote:
> > I'm having 2 AST's (if that doesn't mean anything to you, you can stop
> > reading now ;) and I'd like to compare them. Basically walk them in a
> > synchronous way and on each step compare a couple of values of the
> > current node.
> 
> If 2 AST's are guaranteed to have the same structure (i.e. nodes/children of 
> each node, etc.)

Well, if they don't, thats a reason for the test to fail.

> then I can think of using 2 stacks to traverse the trees. 
> Below is ruby-alike pseudocode;) and I haven't really checked if that works:

Hmm, I thought about something like that, but somehow couldn't quite
"finish" my thoughts - always got into a dead end. But now I think I
have an idea:

An AST walker walks my "generated" Ast and in each visitXX the compare's
are done. For any child nodes it pushes the "expected" ast node onto the
stack and calls the proper visitXX method. Yeah, that should work and
leave me again with a few dozen methods to implement, but being able to
really easily write the tests :)

Of course that might not be the ultimate solution, so other ideas are
welcome still.

Andreas

-- 
Don't plan any hasty moves.  You'll be evicted soon anyway.




More information about the KDevelop-devel mailing list