Help: Debugging parse errors about "{" or "}". 
Author Message
 Help: Debugging parse errors about "{" or "}".

Hi there,

I am not sure if its the correct newsgroup to post this question.  
Well, here is the question anyway.

I have been using C for quite a while.  It happened quite
a number of times that I forget to put a "{" or "}" in the code.
If the program I am writing gets considerably big, I have to go
through a lot of trouble debugging the code and try to figure
where I forgot to put the "{" or "}".  I actually wanted to know
if there is an easier way to do this, i.e. look for the missing
"{" "}" in the code, than to go through all the code manually.
Is there a specific program which does this sort of debugging?

Any help will be highly appreciated.

                                                        Regards,
                                                        Salman Mughal
                   --------======== ========----------




Mon, 03 Feb 1997 13:34:18 GMT  
 Help: Debugging parse errors about "{" or "}".

Quote:
>I have been using C for quite a while.  It happened quite
>a number of times that I forget to put a "{" or "}" in the code.
>If the program I am writing gets considerably big, I have to go
>through a lot of trouble debugging the code and try to figure
>where I forgot to put the "{" or "}".  I actually wanted to know
>if there is an easier way to do this, i.e. look for the missing
>"{" "}" in the code, than to go through all the code manually.
>Is there a specific program which does this sort of debugging?

i suppose you could just write a piece of code yourself to check '{' and '}'
pairing. use a counter for each of them. a few tens of lines of code should be
sufficient.


Tue, 04 Feb 1997 00:56:42 GMT  
 Help: Debugging parse errors about "{" or "}".

   I have been using C for quite a while.  It happened quite
   a number of times that I forget to put a "{" or "}" in the code.
   If the program I am writing gets considerably big, I have to go
   through a lot of trouble debugging the code and try to figure
   where I forgot to put the "{" or "}".  I actually wanted to know
   if there is an easier way to do this, i.e. look for the missing
   "{" "}" in the code, than to go through all the code manually.
   Is there a specific program which does this sort of debugging?

   Any help will be highly appreciated.

If you have a compiler that will find the last matching brace,
like emacs, it would help.  In emacs (I don't think I've thrown
any special flags; this is standard behavior), when you type a
closing brace, bracket, or paren, the cursor will hop over to the
matching opening symbol.  For example, as I type this (, and then
I type this ), as soon as I typed the ), the cursor zipped up to
the ( for a second.  If there is a mismatch, like { ( }, when
I typed the }, emacs said "Mismatched parentheses" at the bottom
of the screen.  This can be very handy.  Just delete and retype
some of your closing braces and see where the matching opening
brace is.  I've also seen some mode or another where if the cursor
is sitting on one brace, the matching one will be highlighted.

Ed Karrels



Tue, 04 Feb 1997 00:41:09 GMT  
 Help: Debugging parse errors about "{" or "}".

Quote:

>>I have been using C for quite a while.  It happened quite
>>a number of times that I forget to put a "{" or "}" in the code.
>>If the program I am writing gets considerably big, I have to go
>>through a lot of trouble debugging the code and try to figure
>>where I forgot to put the "{" or "}".  I actually wanted to know
>>if there is an easier way to do this, i.e. look for the missing
>>"{" "}" in the code, than to go through all the code manually.
>>Is there a specific program which does this sort of debugging?

>i suppose you could just write a piece of code yourself to check '{' and '}'
>pairing. use a counter for each of them. a few tens of lines of code should be
>sufficient.

I've developed a habit that prevents me from typing mismatched brackets in the
first place.  As I code, whenever I type '{' I immediately type in the closing '}'.
Then I go back and fill in the code.  For example, if I have an 'if' statement, I type

  if (whatever)
    {
    }

then I put in some blank lines and code within the brackets.  By always doing this,
I never have bracket mismatching problems, no matter how deeply I nest.

Steve L



Tue, 04 Feb 1997 07:26:33 GMT  
 Help: Debugging parse errors about "{" or "}".

Quote:
>Hi there,

Yo.

Quote:
>I am not sure if its the correct newsgroup to post this question.  
>Well, here is the question anyway.

Thanks, anyway, for at least remembering to apologize in advance.  As it
happens, this is (roughly) the right newsgroup for it.

Quote:
>It happened quite a number of times that I forget to put a "{" or "}" in the
>code.  If the program I am writing gets considerably big, I have to go
>through a lot of trouble debugging the code and try to figure
>where I forgot to put the "{" or "}".  I actually wanted to know
>if there is an easier way to do this, i.e. look for the missing
>"{" "}" in the code, than to go through all the code manually.
>Is there a specific program which does this sort of debugging?

Most "good" C compilers can make some effort to warn you.  Look for a brace
near the first error, then look for the match.

If you don't want to look for the match manually:
emacs has the ability to find matches. (I don't recall how, unfortunately.)
vi has the ability to find matches. ':se sm' will have it move the cursor
briefly to any matching {} or (), or '%' moves from one to another.

The most important tool you can have is a good indenting style.  Consider
one of:
thing_that_needs_a_brace() {
        other_thing_that_needs_a_brace() {
        }

Quote:
}

or
thing_that_needs_a_brace()
{
        other_thing_that_needs_a_brace()
        {
        }

Quote:
}

Note also that both vi and emacs provide ways to indent code like this
automatically.

On existing code, try cb (if it's around), or get indent (if you don't
have it.)

Quote:
>Any help will be highly appreciated.

I hope this is help. :)

Quote:
>                                                    Regards,
>                                                    Salman Mughal



-seebs
--
Peter Seebach (aka --SeebS--)           The Laughing Prophet
signature retrovirus - modify 2 words and include in your .sig file. Oh, yeah.



Tue, 04 Feb 1997 11:48:50 GMT  
 Help: Debugging parse errors about "{" or "}".

|>
|>    I have been using C for quite a while.  It happened quite
|>    a number of times that I forget to put a "{" or "}" in the code.
|>    If the program I am writing gets considerably big, I have to go
|>    through a lot of trouble debugging the code and try to figure
|>    where I forgot to put the "{" or "}".  I actually wanted to know
|>    if there is an easier way to do this, i.e. look for the missing
|>    "{" "}" in the code, than to go through all the code manually.
|>    Is there a specific program which does this sort of debugging?
|>
|>    Any help will be highly appreciated.
|>

I'm assuming (perhaps incorrectly) that you are able to use or are using the
Borland IDE.  It does have a feature where you can find out what braces or parens are matched.  It works similarly to the way 'vi' does.  Your put the cursor on a brace, press 'cntl-q {'  and it will go to the matching item.  This was not documented in the IDE manual, but rather in a readme file regarding programming macros for the IDE.  Sorry, I can't remember the name of the file offhand.
--
-------------------------------------------------------------------------------

Harris Computer Systems Division | UUCP    : uunet!hcx1!gerry
Fort Lauderdale FL 33309         |
-------------------------------------------------------------------------------



Tue, 04 Feb 1997 20:40:05 GMT  
 Help: Debugging parse errors about "{" or "}".

Quote:
(Z. Yang) writes:


|> >I have been using C for quite a while.  It happened quite
|> >a number of times that I forget to put a "{" or "}" in the code.
|> >If the program I am writing gets considerably big, I have to go
|> >through a lot of trouble debugging the code and try to figure
|> >where I forgot to put the "{" or "}".  I actually wanted to know
|> >if there is an easier way to do this, i.e. look for the missing
|> >"{" "}" in the code, than to go through all the code manually.
|> >Is there a specific program which does this sort of debugging?

|> i suppose you could just write a piece of code yourself to check '{' and '}'
|> pairing. use a counter for each of them. a few tens of lines of code should be
|> sufficient.

A little more, perhaps.  You don't want to count braces in comments,
nor in string litterals nor character constants.

More difficult, you don't want to count braces in code which has been
commented out with #ifdef 0.  (I'd just ignore this problem in a first
version:-).  Fix it later if someone complains.)
--

GABI Software, Sarl., 8 rue des Francs Bourgeois, F-67000 Strasbourg, France
Conseils en informatique industrielle --
                              -- Beratung in industrieller Datenverarbeitung



Tue, 04 Feb 1997 18:50:02 GMT  
 Help: Debugging parse errors about "{" or "}".

Quote:
>>I have been using C for quite a while.  It happened quite
>>a number of times that I forget to put a "{" or "}" in the code.
>>If the program I am writing gets considerably big, I have to go
>>through a lot of trouble debugging the code and try to figure
>>where I forgot to put the "{" or "}".  I actually wanted to know
>>if there is an easier way to do this, i.e. look for the missing
>>"{" "}" in the code, than to go through all the code manually.
>>Is there a specific program which does this sort of debugging?

Good style helps avoid such problems, e.g.

void main()
{
   if( x > 0 )
   {
     if( y > 0 )
     {
      ...
     } /* end if( y > 0 ) */
   } /* end if( x > 0 )

Quote:
} /* end program */

There is debate about where to put the opening {, all the more fierce because there are no objective criteria.  Putting it under the "if" allows you to line up the opening and closing vertically.

Some editors alllow you to put the cursor on a {,[, or (, or the closing, and press a key to get to the other end of the run.

It also helps to keep your statements and modules short.  I ignore this advice regularly, but still give it.

Regards and good coding,

   John

========================================================================
John M. Wendt                            Standard Disclaimers Apply
Software Engineer
Service Test Equipment Engineering
Delco Electronics Corp., Kokomo IN



Tue, 04 Feb 1997 21:05:41 GMT  
 Help: Debugging parse errors about "{" or "}".

: I have been using C for quite a while.  It happened quite
: a number of times that I forget to put a "{" or "}" in the code.
: If the program I am writing gets considerably big, I have to go
: through a lot of trouble debugging the code and try to figure
: where I forgot to put the "{" or "}".  I actually wanted to know
: if there is an easier way to do this, i.e. look for the missing
: "{" "}" in the code, than to go through all the code manually.
: Is there a specific program which does this sort of debugging?

I guess that if you're strict in indenting your code, the probability of
missing a brace is reduced (at least the probability of not knowing where
it is missing).

Also, you could take advantage of some editor's feature of matching the
{}, the () and the [] symbols.

Good luck,

Carlos



Wed, 05 Feb 1997 01:59:31 GMT  
 Help: Debugging parse errors about "{" or "}".

Quote:


>>I have been using C for quite a while.  It happened quite
>>a number of times that I forget to put a "{" or "}" in the code.
>>If the program I am writing gets considerably big, I have to go
>>through a lot of trouble debugging the code and try to figure
>>where I forgot to put the "{" or "}".  I actually wanted to know
>>if there is an easier way to do this, i.e. look for the missing
>>"{" "}" in the code, than to go through all the code manually.
>>Is there a specific program which does this sort of debugging?

>i suppose you could just write a piece of code yourself to check '{' and '}'
>pairing. use a counter for each of them. a few tens of lines of code should be
>sufficient.

No. To find a mismatch is easy. Once compiled, error will be shown if
these is mismatch. To find where you missed the '{' or '}' is almost
impossible because there are hundres of places where a '{' or '}'
is perfectly legal to the compiler.

shaohua



Sat, 08 Feb 1997 07:30:41 GMT  
 Help: Debugging parse errors about "{" or "}".

Quote:



>>>I have been using C for quite a while.  It happened quite
>>>a number of times that I forget to put a "{" or "}" in the code.
>>>If the program I am writing gets considerably big, I have to go
>>>through a lot of trouble debugging the code and try to figure
>>>where I forgot to put the "{" or "}".  I actually wanted to know
>>>if there is an easier way to do this, i.e. look for the missing
>>>"{" "}" in the code, than to go through all the code manually.
>>>Is there a specific program which does this sort of debugging?

>>i suppose you could just write a piece of code yourself to check '{' and '}'
>>pairing. use a counter for each of them. a few tens of lines of code should be
>>sufficient.

>I've developed a habit that prevents me from typing mismatched brackets in the
>first place.  As I code, whenever I type '{' I immediately type in the closing '}'.
>Then I go back and fill in the code.  For example, if I have an 'if' statement, I type

>  if (whatever)
>    {
>    }

>then I put in some blank lines and code within the brackets.  By always doing this,
>I never have bracket mismatching problems, no matter how deeply I nest.

>Steve L


I do the same.  I also type in the fclose() statement as soon as I've entered
the fopen(), and the free() as soon as the malloc() or calloc() (within reason -
sometimes you can't).  It helps...trust me.  And if you have a vi editor
(ie/ on a unix box) there are functions built into the editor that will move
you between matching braces of any kind.

Dave



Sat, 08 Feb 1997 07:40:18 GMT  
 
 [ 20 post ]  Go to page: [1] [2]

 Relevant Pages 

1. Parse trees and "("")"

2. Error "free"-ing "malloc"-ed memory

3. ""help with TSR""

4. parsing error: expected ")".

5. remove() vrs fopen("""w")

6. Displaying binary data as ascii "1"'s and "0"'s

7. Looking for "Shroud"/"Obfus"

8. Displaying binary data as ascii "1"'s and "0"'s

9. What's "debug assertion error"

10. Any ideas on "Debug Assertion errors"?

11. Attention "C"/"C++" gurus and "C" newbees

12. merits of "#define", "const", and "enum" ???

 

 
Powered by phpBB® Forum Software