Building Hierarchical Class Tree from custom Scripting Language

J

Jeff Ross

At work I'm using a custom game scripting language, and it's gotten to
be quite bloated. It's fairly similar to Java in that it supports a
lot of class extension.

What I've done so far with Perl is traverse the game tree, found all
the script files, parsed the necessary lines, and now I have an array
that contains hundreds of elements similar to this:

"Class WeaponBaseClass ExtendsFrom GameObject"
"Class StreetLamp ExtendsFrom LightCastera"
"Class AssaultRifle ExtendsFrom WeaponBaseClass"
"Class MoneyClip ExtendsFrom InventoryManager"
"Class GameObject ExtendsFrom BaseGOBJ"
"Class Hud ExtendsFrom RenderMan"

and so on...

Unfortunately, these aren't in any real order..

Since my intention is to thoroughly understand this spaghetti code
system, or at the very least be able to step through the hierarchy
more easily, I would like to find a solution that clearly displays the
parent/child relationships.

I've staged the data so I can easily prepare it for whatever tool or
method I wind up using. Of course it would be ideal to build a UML or
other hyperlinkable visual system.

Any suggestions?

Thanks in advance
 
S

Sam Holden

At work I'm using a custom game scripting language, and it's gotten to
be quite bloated. It's fairly similar to Java in that it supports a
lot of class extension.

What I've done so far with Perl is traverse the game tree, found all
the script files, parsed the necessary lines, and now I have an array
that contains hundreds of elements similar to this:

"Class WeaponBaseClass ExtendsFrom GameObject"
"Class StreetLamp ExtendsFrom LightCastera"
"Class AssaultRifle ExtendsFrom WeaponBaseClass"
"Class MoneyClip ExtendsFrom InventoryManager"
"Class GameObject ExtendsFrom BaseGOBJ"
"Class Hud ExtendsFrom RenderMan"

and so on...

Unfortunately, these aren't in any real order..

Since my intention is to thoroughly understand this spaghetti code
system, or at the very least be able to step through the hierarchy
more easily, I would like to find a solution that clearly displays the
parent/child relationships.

I've staged the data so I can easily prepare it for whatever tool or
method I wind up using. Of course it would be ideal to build a UML or
other hyperlinkable visual system.

Any suggestions?


GraphViz makes reasonable "hierarchical" graph layouts which are a good
fit for inheritance heirarchies (strangely enough :). There's a perl
module on cpan "GraphViz" for ease of use from perl. You would simply
turn each of those string into an edge in the graph and display it:

@data = ("Class WeaponBaseClass ExtendsFrom GameObject",
"Class StreetLamp ExtendsFrom LightCastera",
"Class AssaultRifle ExtendsFrom WeaponBaseClass",
"Class MoneyClip ExtendsFrom InventoryManager",
"Class GameObject ExtendsFrom BaseGOBJ",
"Class Hud ExtendsFrom RenderMan",
);

use GraphViz;
my $g = GraphViz->new();
for (@data) {
if (/^Class (\S+) ExtendsFrom (\S+)$/) {
$g->add_edge($2, $1);
} else {
warn "Unprocessed item: $_\n";
}
}
print $g->as_ps();

And pipe the output to a postscript viewer or to a file. Other output
formats are supported if you don't do postscript.

If there's a viewer you like for some other language, you could also
just munge the text into something syntatically correct (but
meaningless) for that language - with the appropriate names - and use
that viewer.
 
J

Jeff Ross

Thanks for the pointer. It worked perfectly...Now I just need to
explore the intricacies of GraphViz so I can properly output and
visualize my hierarchy of over 400 classes.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top