On Thu, Nov 10, 2016 at 9:18 AM, Richard Wright <
[email protected]> wrote:

> Does anyone know how 4D tokenizes method names? I can get the method
> resource into a blob using API Pack and would very much like to be able to
> extract all methods that are called.


I don't know if there is an easy way, but I'd be glad to hear of one.

The last (and only) time I wrote a parser for this sort of thing was about
15 years ago and I do remember breaking into a sweat several times...I used
"Algorithms" by Sedgewick, which was my go-to algorithms book. (I just
can't follow Knuth...I know his volumes are the standard, or were back
then.) In any case, the problem broke down into a few pieces:

* Define a context-free grammar for the language. This is a set of
rules/expressions describing everything the language might legitimately
contain. In you case, that would include the various symbols 4D uses for
synatax, command words and even the list of method named.

* Walk through the code and parse it based on the rules. What you ned up
with is a tree-structure.

* If you think about a line like $foo := (2*3)+4, you can see that there is
some nesting there. 2 * 3 is resolved, then 6 is added to 4, and then $foo
is assigned the value 10. But it's a tree, and everyone things of
processing trees root-to-branch and from left-to-right. Why? Because that's
what people do with threes most of the time. Well, in this case you want a
leaves-to-root walk. That way you find the "deepest" part of the expression
- 2*3 = 6 - and it feeds into the next expression up the tree. You keep
walking up until you get to the end of the line.

Actually, you might not need that last step as you're not trying to execute
the code.

Hmm. What about this:

* Call METHOD GET NAMES to get a list of all project methods.

* Call METHOD GET CODE to read your target method as readable text.

* Parse the code into a list of words/phrases. (My methods don't uses
spaces, so it would be easy. WIth spaces in names, you would have to
consider word breaks and syntactic characters in detail.)

* Loop over the parsed list of words in the method and check them against
the total list of project methods.

Unless there is an easier way. I haven't slept much....
**********************************************************************
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[email protected]
**********************************************************************

Reply via email to