[antlr-interest] New article on StringTemplates and Treewalkers
Andy Tripp
atripp at jazillian.com
Tue Jan 10 14:40:25 PST 2006
>
>
>I was struck by the example of 5 lines of C code being folded into one
>line of Java code. Why couldn't you have a tree parser do this? It would
>be inefficient, but I don't know if that is the point of the article.
>
You can't have a tree parser look for those 5 lines because
there might be hundreds of different combinations of 5 lines that would
all fold into
that one line of Java code.
In order to write a "look for a chunk of code that is really just doing
a strcpy()" function,
you're going to have to do some real work.
How many ways are there to write your own "strcpy()", each using a few
lines?
You could use a "for" or "while" loop. You can reference the array using
pointer syntax or array syntax,
you can use a pointer to loop through or an index. You can increment the
pointer/index with
i++, ++i, or i=i+1. You could just use strcpy() or strncpy(). You could
wrap strcpy() with your
own macro or function. You could allocate new memory for
the destination string or assume it's already allocated. You could loop
until you hit '\0' or use
strlen().
In order to avoid a combinatorial explosion of various patterns to look
for, you'll need to write
some code that tries to look chunks of code that seem to be doing
strcpy(), and yet is
flexible enough to handles these kinds variations.
Hope that answers the question.
Andy
More information about the antlr-interest
mailing list