An IDE for C

J

jacob navia

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.
 
E

Eric Sosman

jacob said:
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.
 
J

jacob navia

I thought about that
#define BEGIN {
#define END }

etc...

But the alternative (running the preprocessor) is just too heavy.
Wedit will just show an empty index...

No way to please everyone :)

Thanks for your answer.

jacob
 
P

Peter Ammon

jacob said:
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.

Yes, these can appear in "compound literals" (not sure what the
technical name is?) in C99. This is a feature I use a lot.

struct point_t { float x; float y; };
struct point_t point = (struct point_t) {5., 3.};

-Peter
 
P

Peter Ammon

Peter said:
Yes, these can appear in "compound literals" (not sure what the
technical name is?) in C99. This is a feature I use a lot.

struct point_t { float x; float y; };
struct point_t point = (struct point_t) {5., 3.};

-Peter

Oops, you already considered that one. Sorry.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
474,143
Messages
2,570,822
Members
47,368
Latest member
michaelsmithh

Latest Threads

Top