jacob navia wrote:
The IDE of lcc-win32 is specifically done for the C language.
Besides the obvious syntax coloring, we have an automatic
index (which functions are defined in the current document).
For parsing this, no full fledged compilation is necessary. The
algorithm I follow is very simple:
1: Strip comments and char strings.
2: In the remaining text search at level
zero (when no braces have been seen)
for the characters ')' and then '{'.
Those are the starts of the functions in the text.
Scan backwards to gather the definition, forwards
to the next matching closing brace for the body.
This has been working since several years but I have
never proved it. Can it be possible to write in standard
C the character sequence
) ... {
besides at the start of a function definition?
I think C99 allows
struct f { int a,b; };
struct f = (struct f){1,2};
But this is a bit pathological since
struct f = { 1 , 2};
works too.
In any case wedit is not fooled by that, but
besides this one, is there any other I haven't
seen?
Thanks for your time.
The sequence `){' can appear in C99 constructs as
you mention, but the only "level-zero" occurrences I can
think of would be, as you observe, pretty strange.
A function-like macro could confuse the scan, but I
think it would be a pretty unusual macro. And, of course,
macros in general could make the scan arbitrarily ugly:
#define MAINFUNC int main(void)
#define BEGIN {
#define END }
#define RETURN_OK return 0;
MAINFUNC BEGIN
puts("Goodbye, cruel world!");
RETURN_OK
END
Faced with this, an IDE might as well decide that there
are limits to its ability to overcome human folly.
You didn't ask about it, but it occurs to me that
there's a case where a function is *not* introduced by
the sequence `){', namely, "K&R" functions with arguments:
int main(argc, argv)
int argc;
char **argv;
{ ...
If the syntax recognizer can deal with this, it's already
endowed with some ability to disregard material between the
`)' and the `{'.
A final quirk might be
int main(void) <%
puts("O brave new world that hath such creatures in it!");
return 0;
??>
.... but these should be easily dealt with by a very low-
level translation.
--
Er*********@sun.com