A hard challenge anyone?

Marielle Lange mlange at widged.com
Sat Feb 3 16:39:52 EST 2007


> The hard bit is to be able to match the function call - and extract  
> whatever
> is between the brackets - then I can recurse the bit between the  
> brackets if
> it in turn contains a (user defined) function call.

> My guess is that this is something that a regexp could deal with or  
> do I
> have to go back to the techique of counting opening and closing  
> brackets?

Hi David,

To solve a problem of this type, what matters is to be able to  
unambiguously know the status of the "unit" your regular expression  
or whatever has identified. If you go from left to right,  you can't  
because you never know if a "(" parenthesis will be followed by more  
"(" or not.

The minimal unit, that is the unit that you know not to contain any  
further function itself is the ([^)]*) group, which corresponds to  
function(...) where what is enclosed within the parentheses is not  
allowed to contain any parenthesis.

What you may want to try, therefore, is to recurse with a regular  
expression, that looks somehow like this (I let you get the correct  
one):

	[^\b()]*		(	[^)]*	)

(I put tabs for increased legibility; \b means any character that is  
a word boundary... check the doc to be sure this correspond to what  
you want).

The alternative is to look for a ")" character... then look from  
right to left for the first "(" character. You unambiguously know  
this forms a minimal unit. Another alternative, if you insist to go  
from left to right is to look for a pattern of this type "(...)[^)].  
Again, you know you have unambiguously come across a minimal unit  
that doesn't enclose any further unit.

You don't try to find out what functions are enclosed within the big  
ones. You rather try to identify the parent of each function. Once  
you have a table with

node 	parent
bfct		afct
cfct		bfct

you can sort it and read it any way you want.

You may want to run a google search on 'linked list data structure'  
for some additional insights <http://cslibrary.stanford.edu/103/ 
LinkedListBasics.pdf>
<http://www.gamedev.net/reference/programming/features/uds1/>
<http://www.csharpfriends.com/Articles/getArticle.aspx?articleID=176>

Marielle





More information about the use-livecode mailing list