A hard challenge anyone?
Kay C Lan
lan.kc.macmail at gmail.com
Fri Feb 16 00:30:34 EST 2007
On 2/16/07, Phil Davis <revdev at pdslabs.net> wrote:
>
> Kay C Lan wrote:
>
> > PS Origininally tried to replace the tokens with the efficient:
> > put "=, +, -, *, /, [, ], {, }, <, >" into tMyTokens
>
>
> Your list of tokens contains spaces. Did you try your loop without the
> spaces in
> there?
Ah, what a different set of eyes can do:-) That was the problem so here is
the amended script:
Script Below
Watch For Line Breaks
43 lines of code, each starting with it's respective line number
--------
1 FUNCTION fFunctionFinder pMyData
2 put 1 into tMyFunctionOpen
3 put 1 into tMyFunctionClose
4 put "closed" into tMyQuotes
5 put the number of characters of pMyData into tMyCharCount
6 REPEAT with tMyChar = 1 to tMyCharCount
7 SWITCH
8 --needs to occur first so that you know when quotes close
9 CASE ((char tMyChar of pMyData = quote) AND (tMyQuotes = "open"))
10 put "closed" into tMyQuotes
11 break
12 --catch for opening quotes
13 CASE ((char tMyChar of pMyData = quote) AND (tMyQuotes = "closed"))
14 put "open" into tMyQuotes
15 break
16 --the following 3 CASE are irrelevant unless outside quotes
17 CASE ((char tMyChar of pMyData = "(") AND (tMyQuotes = "closed"))
18 put (tMySpaceStore + 1) into item 1 of line tMyFunctionOpen of
tMyFunctionStore
19 put tMyChar into item 2 of line tMyFunctionOpen of tMyFunctionStore
20 add 1 to tMyFunctionOpen
21 put tMyChar into tMySpaceStore
22 break
23 CASE ((char tMyChar of pMyData = ")") AND (tMyQuotes = "closed"))
24 put tMyChar into item 3 of line tMyFunctionClose of tMyFunctionStore
25 add 1 to tMyFunctionClose
26 put tMyChar into tMySpaceStore
27 break
28 CASE ((char tMyChar of pMyData = " ") AND (tMyQuotes = "closed"))
29 put tMyChar into tMySpaceStore
30 break
31 END SWITCH
32 END REPEAT
33 REPEAT for each line tMyLine in tMyFunctionStore
34 put char (item 1 of tMyLine) to (item 2 of tMyLine) of pMyData & ")" &
return after tMyFunctionResult
35 END REPEAT
36 --where function names immediately follows a token, such a comma when
used as a function parameter, then the token is included at the front of the
function name. this removes it
37 put "=,+,-,*,/,[,],{,},<,>,." into tMyTokens
38 REPEAT for each item tMyItem in tMyTokens
39 replace tMyItem with empty in tMyFunctionResult
40 END REPEAT
41 replace comma with empty in tMyFunctionResult
42 return tMyFunctionResult
43 END fFunctionFinder
------
Thanks
More information about the use-livecode
mailing list