Thread: Parse Error

  1. #1
    Registered User
    Join Date
    Jun 2002
    Posts
    39

    Parse Error

    I got a parse error when compliing the following code (its attached). They are on lines 113, 119, and 125. The complier says parse error before '}'.
    Compiler: Dev-C++ 4.9.8.0

    -Bert

  2. #2
    Registered User fletch's Avatar
    Join Date
    Jul 2002
    Posts
    176
    What's in battleKnight.cpp, battleBarbarian.cpp, and battleGoblin.cpp?

    Parse error is usually a 'grammatical' error of some sort, like a missing semicolon. In this case the compilier came across a closing brace when it was expecting something else.
    Last edited by fletch; 07-23-2002 at 04:57 PM.
    "Logic is the art of going wrong with confidence."
    Morris Kline

  3. #3
    Registered User
    Join Date
    Jun 2002
    Posts
    39
    So you think the problem is in "battleKnight", "battleBarbarian", and in "battleGoblin"? Well, I'm gonna attach "battleKnight" to this message. "battleBarabrian", and "battleGoblin" is pretty much the same.
    Compiler: Dev-C++ 4.9.8.0

    -Bert

  4. #4
    Registered User fletch's Avatar
    Join Date
    Jul 2002
    Posts
    176
    Assuming I counted correctly, on line 148 of battleknight.cpp there's an extra '}'

    Extra/missing { } ; ( ) etc, etc...are the kinds of things that normally cause parse errors.

    fletch
    "Logic is the art of going wrong with confidence."
    Morris Kline

  5. #5
    Registered User squireBOB's Avatar
    Join Date
    Dec 2001
    Posts
    6

    Good things come in pairs

    fletch is right look at the last bracket (}) in the file. Where's the matching one? Nada.

  6. #6
    Registered User
    Join Date
    Jun 2002
    Posts
    39
    Okay. It works. Thanks Fletch.
    Compiler: Dev-C++ 4.9.8.0

    -Bert

  7. #7
    Registered User
    Join Date
    Jun 2002
    Posts
    39
    I was updating this program and I came across some errors again. Below (attached) are 2 of the files. It says that there are errors but I can't find them.
    Last edited by Bert; 07-23-2002 at 07:53 PM.
    Compiler: Dev-C++ 4.9.8.0

    -Bert

  8. #8
    Registered User
    Join Date
    Jun 2002
    Posts
    39
    Here's the other file.
    Compiler: Dev-C++ 4.9.8.0

    -Bert

  9. #9
    Registered User fletch's Avatar
    Join Date
    Jul 2002
    Posts
    176
    What were the errors?
    "Logic is the art of going wrong with confidence."
    Morris Kline

  10. #10
    Registered User
    Join Date
    Jun 2002
    Posts
    39
    Line / Unit / Message
    147 / ROA_v3-0.cpp / In file included from ... ROA_v3-0.cpp
    / cityBertopia.cpp / [Warning] In function 'void cityBertopia()'
    51 / cityBertopia.cpp / parse before '{'
    71 / cityBertopia.cpp / 'choice2' undeclared [first use this function]
    / / [Build Error] (Each undeclared identifier is reported only once
    / / [Build Error] for each function it appears in.)
    / / [Build Error] At top level
    147 / ROA_v3-0.cpp / parse error before '}'
    Compiler: Dev-C++ 4.9.8.0

    -Bert

  11. #11
    Registered User fletch's Avatar
    Join Date
    Jul 2002
    Posts
    176
    You're getting creative

    I think that your problem arises from the fact that you've declared the function main2() inside the function cityBertopia(). While I'm not 100% sure that it's illegal per se, I do know that it is definitely poor programming practice. I'd recommend that you move the main2() function out of cityBertopia and see if that solves your problem.

    fletch
    "Logic is the art of going wrong with confidence."
    Morris Kline

  12. #12
    Registered User
    Join Date
    Jun 2002
    Posts
    39
    There isn't a "main2" in "cityBertopia" so I think you mean "menu2". Anyways, "menu2" ISN'T declared in "cityBertopia". Its declared in "ROA_v3-0".
    Compiler: Dev-C++ 4.9.8.0

    -Bert

  13. #13
    Registered User fletch's Avatar
    Join Date
    Jul 2002
    Posts
    176
    Yes, I did mean 'menu2' instead of 'main2'.

    At the top of ROA_v3-0.cpp you've declared a function prototype for menu2(). In fact, you've declared two prototypes for the same funcion. However, there is no code in ROA_v3-0.cpp for menu2().
    Code:
    void cityBertopia()
    {
    #include "cityBertopia.cpp"
    }
    Here you've declared a function cityBertopia(). Because the #include statement is inside the {braces}, everything in the file cityBertopia.cpp is a part of function cityBertopia(). I'll put the two together so that you can see this.
    Code:
    void cityBertopia()
    {
    //Switch Statment
        bool exit = false;
        for ( ; ; )
        {
            int choice2 = menu2();
            switch(choice2)
            {
            //switch statement edited for space
            }
            if (exit)
            break;
        }
    
    //Screen
    int menu2()
    {
    int choice2;
    cout << "The city you are currently in is Bertopia. \n\n";
    
    cout << "**** Menu ****\n\n";
    cout << "(1) Battle \n";
    cout << "(2) Shop \n";
    cout << "(3) Train \n";
    cout << "(4) Check Status \n";
    cout << "(5) Inventory \n";
    cout << "------ \n";
    cout << "(6) Go east or Mordavia \n";
    cout << "(7) Go south to Dinxopolis \n";
    cout << "(8) Go south east to Swamp City. \n";
    cout << "------ \n";
    cout << "(9) Save Game \n";
    cout << "(10) Load Saved Game \n";
    cout << "(11) Quit \n";
    cout << ": ";
    cin >> choice2;
    return choice2;
    }
    }
    Starting with the statement 'int menu2()' you began defining the function menu2(). If you count the braces, it's easy to see that menu2() is being defined inside the function cityBertopia().

    fletch
    "Logic is the art of going wrong with confidence."
    Morris Kline

  14. #14
    Registered User
    Join Date
    Jun 2002
    Posts
    39
    So what would you suggest?
    Compiler: Dev-C++ 4.9.8.0

    -Bert

  15. #15
    Registered User fletch's Avatar
    Join Date
    Jul 2002
    Posts
    176
    I'd recommend that you move the main2() function out of cityBertopia and see if that solves your problem.
    Except that it's menu2(), not main2.
    "Logic is the art of going wrong with confidence."
    Morris Kline

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. How to monitor process creation?
    By markiz in forum Windows Programming
    Replies: 31
    Last Post: 03-17-2008, 02:39 PM
  3. Using VC Toolkit 2003
    By Noobwaker in forum Windows Programming
    Replies: 8
    Last Post: 03-13-2006, 07:33 AM
  4. C++ compilation issues
    By Rupan in forum C++ Programming
    Replies: 1
    Last Post: 08-22-2005, 05:45 AM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 01:10 AM