Thread: Pascal translation

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    15

    Pascal translation

    I am trying to translate a program from Pascal to C. However some statement in pascal confused me and i am not to sure what should I be using instead.

    The statement in question is:

    Code:
    case form: typform of
                       scalarfrm:  ();
                       subrangfrm: ( rangtyp: typtabptr;
                                     min,
                                     max: constrec);
                       enumfrm:    ( maxenum: 0 .. 255);
                       arrayfrm:   ( elemtyp,
                                     indxtyp: typtabptr);
                       recordfrm:  ( lastfld: symtabptr;
                                     recvrnt: typtabptr);
                       tagfrm:     ( tagfldp: symtabptr;
                                     fstvarnt: typtabptr);
                       varntfrm:   ( nxtvarnt,
                                     subvarnt: typtabptr;
                                     varntval: constrec);
                       setfrm:     ( seteltyp: typtabptr;
                                     maxelem: integer);
                       filefrm:    ()
    Now the main issues is the first line form: typform to me is a structure type but again i am not sure if i should be implementing a union, or a case statement

    Thanks

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    That's object oriented programming and you're very unlikely to get it to work in C.

  3. #3
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    What we have here is the complex declaration of a type.
    It's basically a union, or more specifically it's a sort of typesafe union where the compiler pretends that only certain members exist depending upon the variable that indicates the type held in the union.

    You might later use a switch statement where that type is used, but here it's just the type declaration.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  4. #4
    Registered User
    Join Date
    Nov 2011
    Posts
    15
    Thanks for the answer. Yeah it is a complex program, i am trying to make a compiler. So just to be clear if understand the best way to define it would be this way?

    Code:
    typedef struct typrec
    {
        int size;
        union form
        {
            typform scalarfrm;
            typform subrangfrm;
            typform enumfrm;
            typform arrayfrm;
            typform recordfrm;
            typform tagfrm;
            typform varntfrm;
            typform setfrm;
            typform filefrm;
            
        };
    };
    where typform is a enum ( i made it actually a typedef enum) this would be the best way to approach it?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. translation api
    By herWter in forum C Programming
    Replies: 4
    Last Post: 12-11-2008, 02:29 PM
  2. translation!!
    By impossible in forum C++ Programming
    Replies: 14
    Last Post: 05-31-2008, 05:17 PM
  3. C to C++ translation help?
    By bill.thompson65 in forum C++ Programming
    Replies: 5
    Last Post: 10-21-2007, 12:56 PM
  4. translation
    By VOX in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 07-05-2005, 06:21 PM
  5. Translation
    By GaPe in forum C Programming
    Replies: 10
    Last Post: 04-04-2002, 09:45 AM