Page 1 of 1

C enum to PB

Posted: Sat Jul 23, 2005 3:32 am
by jack
how would you translate this to PB:

Code: Select all

typedef enum {a, b, c} tks;

typedef struct tkrec {
  struct tkrec *next;
  tks kind;
  union {
    struct varrec *vp;
    float num;
    Char *sp;
    Char snch;
  } UU;
} tkrec;


Posted: Sat Jul 23, 2005 7:18 pm
by KarLKoX

Code: Select all

Enumeration
   #a
   #b
   #c
EndEnumeration

Structure tkrec
  *next.tkrec
  kind.l
  StructureUnion
    *vp.varrec             ; where is the varrec struct ?
    num.f
    sp.s
    snch.l
  EndStructureUnion
EndStructure
I hope it should work.

Posted: Sat Jul 23, 2005 8:52 pm
by jack
thanks KarLKoX.
to my understanding, an enum in C is a list of constants, so that a 'typedef enum' is a structure of constants?
too bad PB does not accept constants in structures then you could do something like this:

Code: Select all

Structure tks
  Enumeration
    #a
    #b
    #c
  EndEnumeration
EndStructure
actually what I was contemplating on doing was to translate the public domain version of Chipmunk Basic to PB
but it's probably over my head, all this structures and pointers give me a headache.

thanks anyway :)

Posted: Sat Jul 23, 2005 11:18 pm
by griz
I was contemplating on doing was to translate the public domain version of Chipmunk Basic to PB
Interesting... :)

I remember Chipmunk on the Mac years ago. There's always been lots of great resources for writing BASIC interpreters on Ron Nicholson's web page for Chipmunk Basic : http://www.nicholson.com/rhn/basic/.