Correct Identation/Contex can solve the too many compiler error messages problem when a closing brac

K

Keith Thompson

Skybuck Flying said:
The original request was about preventing compilers from generating enormous
ammounts of error messages as soon as a bracket is missing. For example by
programming mistake or accident.

The compiler could do this by looking at the indentation which if used
consistently indicates where a statement block starts and stops.

So at the end of a statement block there should be a closing bracket... if
there isn't the compiler could simply stop right there instead of looking at
the rest of the code etc and generating invalid/crazy/stupid error messages
;)

And how is the compiler supposed to detect the end of a statement
block? The closing brace *defines* the end of a statement block. (At
least it does in C; I'm reading this in comp.lang.c.)

As others have pointed out, there are languages, such as Python, in
which indentation is significant. (Old-style Fortran also requires
rigorous indentation, but that's a bad example.)

And as I mentioned here some time ago, it's possible for a compiler to
use indentation to guess at the intended structure of code, and
thereby give better error messages for missing braces. This doesn't
require indentation to be significant in the language.

None of this is new.
 
S

Skybuck Flying

Keith Thompson said:
And how is the compiler supposed to detect the end of a statement
block? The closing brace *defines* the end of a statement block. (At
least it does in C; I'm reading this in comp.lang.c.)

Lol, easy:

Guess where the opening and closing brackets should be ;)

Something1;
Somethng2;

if (a<b)
Something3;
Something4;
Something5;

Something6;
Something7;
Something8;

if (c<d)
Something9;
Something10;

if (e<f)
Something11;
Something12;
else
Something13;
Something14;
else

if (g<h)
Something15;
Something16;
else
Something17;
Something18;

Something19;
As others have pointed out, there are languages, such as Python, in
which indentation is significant. (Old-style Fortran also requires
rigorous indentation, but that's a bad example.)

And as I mentioned here some time ago, it's possible for a compiler to
use indentation to guess at the intended structure of code, and
thereby give better error messages for missing braces. This doesn't
require indentation to be significant in the language.

Me and the teacher ;) and god knows who else looks forward to seeing this
feature in future compilers ;)

Next time somebody asks this question again I hope people in the comp.lang.c
will answer:

"You have a lazy compiler" ;)

Bye,
Skybuck =D
 
O

Oliver Wong

Skybuck Flying said:
I don't feel there is anything wrong with it lol... but that's just me
being
used to the dutch grammar.

I think Bruce referring to the context-free grammar that describes the
Java language, not your usage of the English grammar.

- Oliver
 
O

Oliver Wong

As a test I loaded this snippet of code into a test.cpp
file and sure enough the code folding quickly identified
the missing bracket.

In other words, this is (and has long been) a solved problem. Something
Skybuck seems to have trouble understanding. :/

- Oliver
 
B

Bruce Roberts

I think Bruce referring to the context-free grammar that describes the
Java language, not your usage of the English grammar.

Actually, since I was posting from a Delphi ng, I was referring to the
context-free grammar that describes Delphi. Not that it makes any
difference. The fact is that the suggestion that layout impart grammatical
structure is not as simple as resolving matching compound statement
bracketing.

In Pascal a While loop has the grammar

While <expression> Do <statement>

With a layout dependant grammar one would have to define it

While <expression> Do <newline> <indent> <statement>

Seems to me to be an awful lot of extra fluff for little gain.
 
O

Oliver Wong

Bruce Roberts said:
Actually, since I was posting from a Delphi ng, I was referring to the
context-free grammar that describes Delphi.

Yeah, immediately after I had hit "send", I said to myself "Oh wait,
this guy crossposted to the C and Delphi guys too, right? Damn."
Not that it makes any
difference. The fact is that the suggestion that layout impart grammatical
structure is not as simple as resolving matching compound statement
bracketing.

In Pascal a While loop has the grammar

While <expression> Do <statement>

With a layout dependant grammar one would have to define it

While <expression> Do <newline> <indent> <statement>

Seems to me to be an awful lot of extra fluff for little gain.

Agreed. And if Skybuck is really serious about this idea, (s)he should
probably move the discussion to comp.compilers where it's more appropriate
to discuss language design issues.

- Oliver
 
A

Andrew McDonagh

Skybuck Flying wrote:

snipped
I agree the choice of {} begin/end etc is irrelevant.

good...

The aligning is most relevant.

bad... you are missing the point....
The pascal style aligns it properly vertically like so:

if a<b then
begin

end;

Some C styles dont align like so:

if (A<b) {

}

snipped

As I said earlier - the real problem is the size of the method.
Trying to help enforce or aid alignment is focusing upon fixing the
symptom - not the real problem.

if your method only contains one use of blocks, then it does not matter
what alignment strategy the language or developer uses.

As soon as another block is needed, its a good indicator that the method
is trying to do more than one job.

so...
 
S

Skybuck Flying

Andrew McDonagh said:
Skybuck Flying wrote:

snipped


bad... you are missing the point....

Nope. You think thing splitting code into multiple methods will solve the
problem somehow.

The point that you are missing is that a missing brace can be an accident ;)
snipped

As I said earlier - the real problem is the size of the method.

No it's not.

The real problem remains the alignment.

It doesn't matter if the code is split up into multiple methods.

The compiler will still produce a storm of error messages if there is a
missing bracket/brace *anywhere* ;)
Trying to help enforce or aid alignment is focusing upon fixing the
symptom - not the real problem.

if your method only contains one use of blocks, then it does not matter
what alignment strategy the language or developer uses.

As soon as another block is needed, its a good indicator that the method
is trying to do more than one job.

so...

Nope lol. A missing bracket/brace can occur on accident.

Bye,
Skybuck.
 
S

Skybuck Flying

Bruce Roberts said:
Actually, since I was posting from a Delphi ng, I was referring to the
context-free grammar that describes Delphi. Not that it makes any
difference. The fact is that the suggestion that layout impart grammatical
structure is not as simple as resolving matching compound statement
bracketing.

In Pascal a While loop has the grammar

While <expression> Do <statement>

With a layout dependant grammar one would have to define it

While <expression> Do <newline> <indent> <statement>

Seems to me to be an awful lot of extra fluff for little gain.

That's not how you would parse it.

There would be something like an indentation count.

As soon as it increases a new statement block begins, as soon as it
decreases the end of a statement block has been reached.

However I like writing code like this in case there are many parameters:

if function(
a,b,c,d,
e,f,g,h,
i,j,k,l ) then
begin
blabla;
end;

This would be a problem unless parameters have to be passed in a special
way.. for example
by using twice the indentation:

if function(
a,b,c,d,
e,f,g,h,
i,j,k,l ) then
begin
blabla;
end;

Which would look like:

if function(
a,b,c,d,
e,f,g,h,
i,j,k,l ) then
blabla;

:)

Bye,
Skybuck.
 
S

Skybuck Flying

Oliver Wong said:
In other words, this is (and has long been) a solved problem. Something
Skybuck seems to have trouble understanding. :/

No I am not aware of any C IDE which does what you say ?

So from your description it would seem the editor loads a file and
completely folds it ???

Or did you fold it yourself manually which is ofcourse retarded... why do it
manually ?

The point is ease of use... so let the compiler or editor do it for you...
which is what this is all about.

Bye,
Skybuck.
 
S

Skybuck Flying

Oliver Wong said:
In other words, this is (and has long been) a solved problem. Something
Skybuck seems to have trouble understanding. :/

After reading your posts I decided to give it a try in visual studio .net
2003. It simply folds the code no matter if there are any missing braces so
at least in this IDE first of all it doesnt find the missing brace and
second of all I had to do it all manually.

// Test.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[])
{
int a,b,c,sdfd,sqfd,dddd,dsdfssdf;
if (a<b)
{
if (sdfd<c)
{
}
if (sqfd<342563)
{
} else
{
}
if (dddd=234)
{
if (dsdfssdf=23)
{
}
}
return 0;
}
Oh look at that it didn't copy paste it right... well blame it on microsoft
outlook... not going to fix it *again* lol :)
Bye,
Skybuck.
 
S

Skybuck Flying

Oliver Wong said:
In other words, this is (and has long been) a solved problem. Something
Skybuck seems to have trouble understanding. :/

Hmm ok for some reason the previous message did not arrive at my newsreader.

Now I see what he is talking about ;) (Some kind of external editor called
zeus ;))

(Kinda strange that post didnt reach me, anybody have any idea why that is
???)

Ok I installed zeus and paste the code into it, the final result is lol:

You're an idiot.

It doesn't detect jack squat. (It simply folds everything etc lol
hahahahahaha)

Bye,
Skybuck.
 
B

Bruce Roberts

That's not how you would parse it.

It doesn't matter how you would parse it. What matters is how the parser
would parse it. You might want to remember that the parser is doing the work
and it is limited to processing a non-ambiguous grammar.
There would be something like an indentation count.

As soon as it increases a new statement block begins, as soon as it
decreases the end of a statement block has been reached.

And what exactly defines an indent? <newline> followed by <space> or <tab>?
And what if there is a mixture? And how does the parser know what expansion
However I like writing code like this in case there are many parameters:

if function(
a,b,c,d,
This would be a problem unless parameters have to be passed in a special
way.. for example
by using twice the indentation:

In Delphi / Pascal the parser has no problems with this since it is working
from a grammar that distinguishes actual parameters from statements. It
might be a problem in C derivatives since an expression can be a statement.
 
S

Skybuck Flying

Bruce Roberts said:
It doesn't matter how you would parse it. What matters is how the parser
would parse it. You might want to remember that the parser is doing the work
and it is limited to processing a non-ambiguous grammar.


And what exactly defines an indent? <newline> followed by <space> or
<tab>?

Lookup the basic concept of indentation lol, shouldn't be to hard to grasp.

Here is what you do:

Turn the text into lines.

Then process each line.

How hard would that be ?

And ofcourse tab characters would be mandatory.
And what if there is a mixture? And how does the parser know what expansion
setting a user's editor was using for <tab> at the time the source was
created?

See above.
In Delphi / Pascal the parser has no problems with this since it is working
from a grammar that distinguishes actual parameters from statements. It
might be a problem in C derivatives since an expression can be a
statement.

Problem solved above.

Bye,
Skybuck.
 
E

Ed Prochak

Skybuck Flying wrote:
[]
;)

The original request was about preventing compilers from generating enormous
ammounts of error messages as soon as a bracket is missing. For example by
programming mistake or accident.

What is the big deal. The compiler dumps a lot of error messages you
look at the first one or two, fixing them, and you get to the third one
which doesn't make sense, so you just save your changes and compile
again. If it was a bracket error, most of the other errors all go away.
The compiler could do this by looking at the indentation which if used
consistently indicates where a statement block starts and stops.

I thought we managed to get beyond fixed format code, like FORTRAN II,
a long time ago. Now you want to make it worse by indicating blocks by
indentation. It is not the compiler that has to put in the indentation,
it is you, the programmer. I prefer my freeform C code, Thank you very
much.
So at the end of a statement block there should be a closing bracket... if
there isn't the compiler could simply stop right there instead of looking at
the rest of the code etc and generating invalid/crazy/stupid error messages
;)

Some compilers have options to have it stop after a certain number of
errors. If you are having so much trouble with closing your code
blocks, try switching that on so you have less to deal with when the
compiler barfs on your code. Personally I haven't had this problem due
to a missing close brace for a LONG (years at least.)
Bye,
Skybuck.

Like a similar discussion you started, I think you have a solution
looking for a problem.

Here's the big problem I see with this. You turned the problem of
errors due to missing a SINGLE closing brace into a duty of the
programmer to make sure EVERY line within the code block is indented to
the same level (and exactly how that gets done is still TBD). Not a
good solution in my view.

HTH,

ed
 
O

Oliver Wong

Ed Prochak said:
What is the big deal. The compiler dumps a lot of error messages you
look at the first one or two, fixing them, and you get to the third one
which doesn't make sense, so you just save your changes and compile
again. If it was a bracket error, most of the other errors all go away.

Incidentally, this is also a "solved" problem in compiler theory. There
are algorithms for detecting when one error is the result of another error,
and to supress those "derivative" error messages.

- Oliver
 
E

Ed Prochak

Skybuck said:
In Pascal a While loop has the grammar

While <expression> Do <statement>

With a layout dependant grammar one would have to define it

While <expression> Do <newline> <indent> <statement>

Seems to me to be an awful lot of extra fluff for little gain.

That's not how you would parse it.

There would be something like an indentation count.

As soon as it increases a new statement block begins, as soon as it
decreases the end of a statement block has been reached.

However I like writing code like this in case there are many parameters:
[]

This would be a problem unless parameters have to be passed in a special
way.. for example
by using twice the indentation:

if function(
a,b,c,d,
e,f,g,h,
i,j,k,l ) then
begin
blabla;
end;

Which would look like:

if function(
a,b,c,d,
e,f,g,h,
i,j,k,l ) then
blabla;

:)

Bye,
Skybuck.

Care to present a grammer for this "indented block" structure?
Code examples don't count.

I don't think a valid grammer for this style can be written in a
context free grammer. In order to keep tract of the block level the
inner level must somehow know the level of the outer block. IOW the
block level is not context free. Bruce's example doesn't work for
anything beyond while loops with a single simple statement. (no sub
blocks like another WHILE or IF)

So show how serious you are by getting down in the works and get it to
happen.

And I agree with others that this solution is worse than the original
problem of missing a block bracket.
Enjoy,
ed
 
S

Skybuck Flying

Ed Prochak said:
Skybuck Flying wrote:
[]
;)

The original request was about preventing compilers from generating enormous
ammounts of error messages as soon as a bracket is missing. For example by
programming mistake or accident.

What is the big deal. The compiler dumps a lot of error messages you
look at the first one or two, fixing them, and you get to the third one
which doesn't make sense, so you just save your changes and compile
again. If it was a bracket error, most of the other errors all go away.

Well what you rather have:

Storm of bullshit.

Or storm of handy hints and error messages =D

Any sane person would prefer the second one ;)

So it's simply an improvement thing I guess... though you should ask the
teacher.. maybe his students started fucking up all the code ;)
I thought we managed to get beyond fixed format code, like FORTRAN II,
a long time ago. Now you want to make it worse by indicating blocks by
indentation. It is not the compiler that has to put in the indentation,
it is you, the programmer. I prefer my freeform C code, Thank you very
much.

Fine, the compiler could still use the indentation to provide any possibly
hints and prevent bs-storm ;)
Some compilers have options to have it stop after a certain number of
errors. If you are having so much trouble with closing your code
blocks, try switching that on so you have less to deal with when the
compiler barfs on your code. Personally I haven't had this problem due
to a missing close brace for a LONG (years at least.)

Lol, how often do you program ? Once every 3 years ? ;)
Like a similar discussion you started, I think you have a solution
looking for a problem.

Nope problem is real look at any compiler today ;)
Here's the big problem I see with this. You turned the problem of
errors due to missing a SINGLE closing brace into a duty of the
programmer to make sure EVERY line within the code block is indented to
the same level (and exactly how that gets done is still TBD). Not a
good solution in my view.

Ahhhh see my second solution: automatic and mandatory indentation ;)

See how the pieces of the puzzle fit together ? =D

Bye,
Skybuck.
 
S

Skybuck Flying

Oliver Wong said:
Incidentally, this is also a "solved" problem in compiler theory. There
are algorithms for detecting when one error is the result of another error,
and to supress those "derivative" error messages.

Sure wong. After reading your previous bullshit about folding... I'll take
this post with a grain of salt.

I know the delphi compiler does a fine job of stoping bs-storms ;) but
delphi is a class of it's own.

C compilers on the other hand LOLOLOLOLOLOLOLOL.

That's all I can say about C compilers LOLOLOL.

Bye,
Skybuck =D
 
S

Skybuck Flying

Ed Prochak said:
Skybuck said:
In Pascal a While loop has the grammar

While <expression> Do <statement>

With a layout dependant grammar one would have to define it

While <expression> Do <newline> <indent> <statement>

Seems to me to be an awful lot of extra fluff for little gain.

That's not how you would parse it.

There would be something like an indentation count.

As soon as it increases a new statement block begins, as soon as it
decreases the end of a statement block has been reached.

However I like writing code like this in case there are many parameters:
[]

This would be a problem unless parameters have to be passed in a special
way.. for example
by using twice the indentation:

if function(
a,b,c,d,
e,f,g,h,
i,j,k,l ) then
begin
blabla;
end;

Which would look like:

if function(
a,b,c,d,
e,f,g,h,
i,j,k,l ) then
blabla;

:)

Bye,
Skybuck.

Care to present a grammer for this "indented block" structure?
Code examples don't count.

I don't think a valid grammer for this style can be written in a
context free grammer. In order to keep tract of the block level the

Who cares about context free grammer. I dont care about.

I am all for context.

Runtime information is a sort of context.
inner level must somehow know the level of the outer block. IOW the
block level is not context free. Bruce's example doesn't work for
anything beyond while loops with a single simple statement. (no sub
blocks like another WHILE or IF)

So show how serious you are by getting down in the works and get it to
happen.

Lol, Why should I ? Python already does it.
And I agree with others that this solution is worse than the original
problem of missing a block bracket.

Then I guess you wont be programming in python lol ;)

(where there are no brackets in the first place lol =D)

Bye,
Skybuck.
 

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

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,131
Latest member
IsiahLiebe
Top