Thread: Parse error before

  1. #1
    Registered User
    Join Date
    Aug 2011
    Posts
    5

    Parse error before

    Hi, I am migrating the C (messy)programs from HP-UX(cc compiler) to AIX(gcc 3.3.2)

    Code:
    double timebegin,timeend;
    struct timeval tp;
    struct timezone tz;
    
    RFC_RC WIN_DLL_EXPORT_FLAGS cll_z_za0007_send(RFC_HANDLE hRfc) {
    
      /* RFC variables */
      unsigned crow;  
      static RFC_RC RfcRc;
      char s[1024];
    
      int i, k = 0, loc = 0, col, x, quan;
      char key[41], plant[5], csmat[11], cemat[11], cquan[4];
      unsigned long nsmat = 0, nemat = 0, nquan = 0;
    
      struct lead
      {
          unsigned long sapno;
          int deltime;
      };
      struct lead leadrec[1000];
      struct lead *leadacc;
      char delsap = 'S';
      char charsapno[19], chardeltime[4];
      int lrec = 0;
    
      /* char p[4097]; */
      char p[10000];
      int nLine=0;
    
      /* param variables */
      MSGNO iMsgno;//import par~var
      MSGV1 iMsgv1;
      SYST_MSGTY eZconfirm;
      ITAB_H thItab = ITAB_NULL;
      char xException[256];  
    
       /* table row variables */
        ZA0007 *tItab;
    
      /* init tables ------------------------------*/
      if (thItab==ITAB_NULL) {
        thItab = ItCreate("ITAB",sizeof( ZA0007),0,0);
        if (thItab==ITAB_NULL) rfc_error("ItCreate ITAB"); }
       else {
          if (ItFree(thItab) != 0) rfc_error("ItFree ITAB"); }
      
    
      /* input export parameters --------------------*/
      TRC((rlog.trc, "exporting parameters..."));
      SETCHAR(eZconfirm,"");
      SETCHAR(eZconfirm,"N");
        
      /* input table rows */
      memcpy(iMsgno.Msgno,"000",3);    
      /*iMsgno.Msgno[3]='\x0';it*/
            
      PRT((rlog.prt,  ">>ZSAART:%s ZZSYS:%s", eZsaart.Zsaart, eZzsys.Zzsys ));/* del eZsaart.Zsaart*/
      TRC((rlog.trc,    "ZSAART:%s ZZSYS:%s", eZsaart.Zsaart, eZzsys.Zzsys ));/* del eZsaart.Zsaart*/
      /* call RFC function */
      sprintf((char *)function_name, "z_za0007_send");
      while ( !strncmp(iMsgno.Msgno, "000", 3) ){
    
        /* del RfcRc = z_za0007_send1(hRfc */
        alarm(300);
        RfcRc = z_za0007_send(hRfc
                ,&eZconfirm
                ,&eZsaart
                            ,&eZzsys
                            ,&iMsgno
                            ,&iMsgv1
                ,thItab
                            ,xException) ;
    
        switch (RfcRc) {
    
            case RFC_OK :
              /* display importing parameters */
              TRC((rlog.trc, "importing..."));          
                        
              /*GETCHAR(iMsgno.Msgno,s);*/
              TRC((rlog.trc, "MSGNO:%s", iMsgno.Msgno));
                                  
              /*GETCHAR(iMsgv1.Msgv1,s);it*/
              TRC((rlog.trc, "MSGV1:%s",iMsgv1.Msgv1));
    
              if(ItFill(thItab) == 0) {
            PRT((rlog.prt, "<<%s",s));
            /*TRC((rlog.trc, "<<%s",s));*/
          }else{
                gettimeofday(&tp,&tz);
                timebegin=tp.tv_sec+(double)tp.tv_usec/1000000;
              PRT((rlog.prt, "Total %d Record(s)",ItFill(thItab) ));
              TRC((rlog.trc, "Total %d Record(s)",ItFill(thItab) ));
          }
          /* display tables */
    
          nLine=0;
    
              for (crow = 1;crow <= ItFill(thItab); crow++) {
                    PRT((rlog.prt, "<<crow: %d, ItFill(thItab):%d", crow, ItFill(thItab) ));
                    tItab = ItGetLine(thItab,crow);
                    if (tItab == NULL) rfc_error("ItGetLine ITAB");
                
                /*GETNUM(tItab->Zkommid,s);
            PRT((rlog.prt,  "<<Zkommid:%s",  s));
            sprintf(s,"%d of %d lines",crow,ItFill(thItab));*/
    
                    if (!strcmp(eZsaart.Zsaart, "H013"))
            {
                strncpy(key, tItab->Zvkey, sizeof(tItab->Zvkey));
                key[sizeof(tItab->Zvkey)] = '\0';
                /* PRT((rlog.prt, "<<Key:%s", key)); */
                        
                col = 1;
                quan = 0;
                loc = 0;
                        for (i = 0; i < 41; i++)
                {
                if (key[i] == ';')
                {
                    if (col == 1)
                    {
                        x = 0;
                    if (loc == i)
                    {
                            plant[x] = '\0';
                    }
                    {
                            for (k = loc; k < i; k++)
                            {
                            plant[x] = key[k];
                            x++;
                                        }
                            plant[x] = '\0';
                                    }
                        loc = i + 1;
                    col++;
                                }
                    else if (col == 2)
                    {
                        x = 0;
                    if (loc == i)
                    {
                            nsmat = 0;
                    }
                    {
                            for (k = loc; k < i; k++)
                            {
                            csmat[x] = key[k];
                            x++;
                            }
                            csmat[x] = '\0';
                            nsmat = atol(csmat);
                                    }
                        loc = i + 1;
                    col++;
                    }
                    else if (col == 3)
                    {
                        x = 0;
                    if (loc == i)
                    {
                            nemat = 0;
                    }
                    {
                            for (k = loc; k < i; k++)
                            {
                            cemat[x] = key[k];
                            x++;
                            }
                            cemat[x] = '\0';
                            nemat = atol(cemat);
                                    }
                        loc = i + 1;
                    col++;
                    }
                    else if (col == 4)
                    {
                        x = 0;
                    if (loc == i)
                    {
                    }
                    {
                            for (k = loc; k < i; k++)
                            {
                            cquan[x] = key[k];
                            x++;
                            }
                            cquan[x] = '\0';
                            nquan = atol(cquan);
                                    }
                        loc = i + 1;
                    col++;
                    break;
                    }
                            }
                        }
    
                        if (plant[0] == '\0')
                   PRT((rlog.prt, "<<Oview<<No plantinfkey available"))
                        if (nsmat == 0)
                   PRT((rlog.prt, "<<Oview<<No firstmatkey available"))
                        if (nemat == 0)
                   PRT((rlog.prt, "<<Oview<<No lastmatkey available"))
                        if (nquan == 0)
                   PRT((rlog.prt, "<<Oview<<No quankey available"))
                    PRT((rlog.prt, "<<plant: %s", plant));
                    PRT((rlog.prt, "<<nsmat: %lu", nsmat));
                    PRT((rlog.prt, "<<nemat: %lu", nemat));
                    PRT((rlog.prt, "<<nquan: %lu", nquan));
                
                tItab->Zvardata[tItab->Zdataln] = '\0';
                sprintf(p, "%s;", tItab->Zvardata);
                PRT((rlog.prt,  "<<%s",  p));
    
                leadacc = leadrec;
                lrec = 0;
                        loc = 5;
                for (i = 5; i < tItab->Zdataln + 1; i++)
                {
                if (p[i] == ';')
                {
                    if (delsap == 'S')
                    {
                                    x = 0;
                    for (k = loc; k < i; k++)
                    {
                        635:if isdigit(p[k])
                        {
                            charsapno[x] = p[k];
                                        }
                                        else
                        {
                        charsapno[0] = '0';
                        x = 0;
                        k = i;
                                        }
                        x++;
                    }
                    charsapno[x] = '\0';
                    loc =  i + 1;
                                    leadacc->sapno = atol(charsapno);
                    delsap = 'D';
                    }
                    652: else
                    {
                                    x = 0;
                    for (k = loc; k < i; k++)
                    {
                        if (x < 3)
                                        {
                            chardeltime[x] = p[k];
                                        }
                        else
                        {
                        chardeltime[0] = '0';
                        x = 0;
                        k = i;
                                        }
                        x++;
                    }
                    chardeltime[x] = '\0';
                    loc = i + 1;
                    leadacc->deltime = atoi(chardeltime);
                    leadacc++;
                    lrec++;
                    delsap = 'S';
                    }
                }
                }
                leadacc = leadrec;
                for (k = 1; k <= lrec; k++)
                {
                if (k == 1 && leadacc->sapno != nsmat)
                    PRT((rlog.prt, "<<Oview<<firstmatkey != firstmatset: %lu != %lu", nsmat, leadacc->sapno))
                            if (k == lrec && leadacc->sapno != nemat)
                    PRT((rlog.prt, "<<Oview<<lastmatkey != lastmatset: %lu != %lu", nemat, leadacc->sapno))
                            if (lrec != nquan)
                    PRT((rlog.prt, "<<Oview<<numkey != numset: %lu != %i", nquan, lrec))
                        write_ams2_lt(leadacc->sapno, plant, leadacc->deltime);
                    PRT((rlog.prt, "<<sap_no[%u] = %lu  ---   leadtime[%u] = %d", k, leadacc->sapno, k, leadacc->deltime));
                leadacc++;
                }
            }
            692:else
            {
                 tItab->Zvardata[tItab->Zdataln]='\0';
                sprintf(p, "%s%s;", PRE_R3LOV, tItab->Zvardata);
                write_ams2(p, strlen(p));
                PRT((rlog.prt,  "<<%s",  p));
                    }
    
            700:nLine++;
                    701:PRT((rlog.prt, "<<loop end crow: %d, nLine:%d", crow, nLine));
        }
    
            if(ItFill(thItab) != 0) {
              gettimeofday(&tp,&tz);
              706:timeend=tp.tv_sec+(double)tp.tv_usec/1000000;
              707:PRT((rlog.prt, "%d Record(s) processed in %ld [seconds]",nLine, timeend-timebegin));
              708:TRC((rlog.trc, "%d Record(s) processed in %lf [seconds]",nLine, timeend-timebegin ));
        }
        710:SETCHAR(eZconfirm,"Y");    /*"Y"*/
            711:TRC((rlog.trc, "ZCONFIRM:'%s' confirmation sent",eZconfirm));
            break;
    
            case RFC_EXCEPTION :
                  /* exception raised */          
                  fprintf(stderr, "%s raised.",xException);                    
            717:ERR((rlog.err, "%s raised.",xException));
            718:rfc_error("rfc exception.");          
            case RFC_SYS_EXCEPTION :
            rfc_error("system exception raised");
            case RFC_FAILURE :
            rfc_error("failure");
            default :
            rfc_error("other failure");
          }
      }
    
      /* delete tables */
      if (ItDelete(thItab) != 0)
        rfc_error("ItDelete ITAB");
    
      return RfcRc;
    }
    /*** rfc_error() ******/
    void rfc_error(char *operation) {
    
      RFC_ERROR_INFO RfcErrorInfo;
      ERR((rlog.err, "RFC error."));
    
      ERR((rlog.err, "operation:%s.", operation));
    
      memset(&RfcErrorInfo,0,sizeof(RfcErrorInfo));
      RfcLastError(&RfcErrorInfo);
      ERR((rlog.err, "key:%s", RfcErrorInfo.key));
    
      ERR((rlog.err, "status:%s", RfcErrorInfo.status));
    
      ERR((rlog.err, "message:%s", RfcErrorInfo.message));
    
      ERR((rlog.err, "internal status:%s", RfcErrorInfo.intstat));
    
      RfcClose (RFC_HANDLE_NULL);
    
      if( clean_up() == 0)
          TRC((rlog.trc, "DISCONNECTED from ORACLE..."));
    
      TRC((rlog.trc,  "END UP with exception. see %s file", err));
    
      if (outfile!=NULL) fclose(outfile);
      if(rlog.prt!=NULL) fclose(rlog.prt);
      if(rlog.err!=NULL) fclose(rlog.err);
      if(rlog.trc!=NULL) fclose(rlog.trc);
    
      exit(1);
    }
    Please help me to resolve this.
    Note: Since this is my first post on a forum, so please apologize, if the inputs provided are in not in a good format.The line numbers are mentioned in the sour

    Thanks.

  2. #2
    Registered User
    Join Date
    Aug 2011
    Posts
    5
    The compilation error:
    Code:
    compiling ...
    r3lov.c: In function `cll_z_za0007_send':
    r3lov.c:635: error: parse error before "isdigit"
    r3lov.c:652: error: parse error before "else"
    r3lov.c:692: error: parse error before "else"
    r3lov.c: At top level:
    r3lov.c:700: error: parse error before '++' token
    r3lov.c:701: error: parse error before '.' token
    r3lov.c:701: error: parse error before '.' token
    r3lov.c:701: error: parse error before '}' token
    r3lov.c:706: error: conflicting types for `timeend'
    r3lov.c:13: error: previous declaration of `timeend'
    r3lov.c:707: error: parse error before '{' token
    r3lov.c:707: error: parse error before '.' token
    r3lov.c:707: error: parse error before '.' token
    r3lov.c:707: error: parse error before '}' token
    r3lov.c:708: error: parse error before '.' token
    r3lov.c:708: error: parse error before '.' token
    r3lov.c:708: error: parse error before '}' token
    r3lov.c:710: error: parse error before string constant
    r3lov.c:711: error: parse error before '.' token
    r3lov.c:711: error: parse error before '.' token
    r3lov.c:711: error: parse error before '}' token
    r3lov.c:717: error: parse error before '.' token
    r3lov.c:717: error: parse error before '.' token
    r3lov.c:717: error: parse error before '}' token
    r3lov.c:718: error: parse error before string constant

  3. #3
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    You need to take the phrase "parse error before" literally. That implies a C syntax error on your part.

    for example, the first refers to this:
    Code:
    635:if( isdigit(p[k]) )
    Start at the top of the digest and work your way through each error. Sometimes if you click the error in a IDE, the line will be highlighted for you.

  4. #4
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Have you actually bothered to look at the code corresponding to the error messages?

    For example, line 635 (which triggers the first error) is
    Code:
                        635:if isdigit(p[k])
    and line 652 (which triggers the second error) is
    Code:
                        652: else
    That sort of placement of digits, followed the the semi-colon, then a valid token is invalid. Hence the compiler complaining about "parse error before ....".

    I haven't looked further than that, but given that the cause of the first two errors is blindingly obvious, I suggest you apply effort yourself to find the other errors.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  5. #5
    C <3er
    Join Date
    Jul 2011
    Posts
    46
    @grumpy I think those digits followed by the semi-colon are for us to find the lines aren't they?
    Anyway he is missing some brackets after the if statement it should be:
    Code:
    if (isdigit(p[k]))
    and not:
    Code:
    if isdigit(p[k])
    I'm on a hurry so couldn't take the time to look at the full code but maybe the errors are propagating from those missing brackets try to correct and compile again. Hope it helps

    P.S: sorry I think whiteflags was faster and better explaining what you should do so follow his tips.
    Last edited by beta3designs; 08-19-2011 at 05:30 AM.

  6. #6
    Registered User
    Join Date
    Aug 2011
    Posts
    5
    Hi All,

    Thanks for your precious time to look into this :-)

    And, yes as you mentioned the line numbers like "635:", is just to show you the line numbers.

    However, I'll try to figure it out in the meantime. What I dont understand is, the same code works on HP UX(cc) but not on AIX.

  7. #7
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by arpr05 View Post
    However, I'll try to figure it out in the meantime. What I dont understand is, the same code works on HP UX(cc) but not on AIX.
    Not to worry... *everything* HP is weird.

  8. #8
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    If you can, check your HPUX sources; if cc accepts
    Code:
    if isdigit(p[k])
    without parentheses, then you probably let HP know about it.

  9. #9
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Quote Originally Posted by arpr05 View Post
    However, I'll try to figure it out in the meantime. What I dont understand is, the same code works on HP UX(cc) but not on AIX.
    Most compilers support "extensions", and this is presumably one of them. That generally means some feature that the vendor, or its development team, think is a good thing.

    In this case, someone on the HP UX(cc) development team probably had a background in Pascal, or some language derived from Pascal, like Ada.

    It is the sort of thing that would be introduced by a programming language zealot/bigot, not through a management decision. A lot of people with a Pascal background think C needs to be improved so it becomes more like Pascal.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  10. #10
    Registered User TheBigH's Avatar
    Join Date
    May 2010
    Location
    Melbourne, Australia
    Posts
    426
    Quote Originally Posted by grumpy View Post
    It is the sort of thing that would be introduced by a programming language zealot/bigot, not through a management decision. A lot of people with a Pascal background think C needs to be improved so it becomes more like Pascal.
    Haha. I think either you or they have drastically misunderstood the meaning of the word "improve".

    In my opinion, Pascal is a hideously repulsive language whose sole redeeming feature is that it's not Haskell.
    Code:
    while(!asleep) {
       sheep++;
    }

  11. #11
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Quote Originally Posted by TheBigH View Post
    Haha. I think either you or they have drastically misunderstood the meaning of the word "improve".

    In my opinion, Pascal is a hideously repulsive language whose sole redeeming feature is that it's not Haskell.
    I didn't suggest that making C look like Pascal represents an improvement. Some people would though.

    Programming language bigotry does not only appear as advocacy of a particular language though, as you have demonstrated.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  12. #12
    Registered User TheBigH's Avatar
    Join Date
    May 2010
    Location
    Melbourne, Australia
    Posts
    426
    Quote Originally Posted by grumpy View Post
    Programming language bigotry does not only appear as advocacy of a particular language though, as you have demonstrated.
    Bigotry arises from prejudice- i.e. judging things before you really know anything about them. If I started ranting about ALGOL or COBOL, which I've never used, because I'd heard other people say they're useless and outdated you might have a point. My dislike of the two languages I mentioned come from having used them, and I certainly don't badmouth other languages just because they're not my first choice. Still have a soft spot for BASIC since that was the language I learnt as a kid (self taught- result was goto-riddled spaghetti code hell until I learned better), and I don't mind Fortran at all.

    I studied Haskell for a semester at university and I didn't like it because it was slow and full of confusing circumlocutions; although looking back I can see it improved my understanding of C functions, particularly recursion, and also helped me do more with shell scripts.

    Pascal annoyed me, firstly because its weird structure isn't to my taste at all, and secondly because it has this vibe that it's enforcing someone else's programming philosophy on me rather than allowing me the freedom to code in my own style. This tends to make me defensive when I hear of Pascal trying to encroach on C's turf. Another reason I believe C is superior is that C code translated into Pascal tends to still be somewhat elegant, while Pascal translated to C usually isn't. C has a kind of common sense simplicity and flexibility that other languages don't, and that's why I like it.

    I don't think making a judgment on a programming language based on my experiences and impressions of it make me a bigot.
    Code:
    while(!asleep) {
       sheep++;
    }

  13. #13
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Bigot (n): someone who is intolerant of any differing creed, belief, opinion, or preference.

    TheBigH, it is fine, as you have done in your last post, to give a basis for your comments. That way people can decide, for themselves, if your views are relevant to them and their circumstances. Your previous post made blanket statements in an absolute manner, so I interpreted that as bigotry. If you don't like being described as a bigot, try to remember to provide context when you express judgements.

    What annoys you about Pascal is that it is doing exactly what it was designed to do: encouraging specific practices that, when Pascal was designed, were considered best practices for structured programming and data structures. Just because a language isn't to your taste, doesn't mean it is horrid for everyone.

    Haskell is a functional programming language. Functional programming tends to annoy people who are not used to that paradigm.

    There are anti-C bigots who hate exactly the features you love about C: the flexibility that makes it easier to get in trouble, things like pointers that really can really be used to screw things up.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  14. #14
    Registered User
    Join Date
    Aug 2011
    Posts
    5

    It is Solved

    Thanks for all.

    BTW, I fixed this issue.

    Just removed the outer parenthesis and compiled --> same errors
    Again placed the parenthesis and compiled --> no error

    Strange!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Parse error before 'int'
    By thealmightyone in forum C Programming
    Replies: 4
    Last Post: 02-05-2009, 02:13 PM
  2. 'Parse error before X'...
    By Alastor in forum C Programming
    Replies: 4
    Last Post: 10-02-2005, 11:21 AM
  3. parse error
    By jrk in forum C++ Programming
    Replies: 3
    Last Post: 12-09-2003, 01:11 PM
  4. Parse error
    By Andystudent in forum C Programming
    Replies: 3
    Last Post: 12-01-2003, 09:31 AM
  5. parse error
    By DMaxJ in forum C Programming
    Replies: 7
    Last Post: 06-30-2003, 08:54 PM