/* Output from p2c --VERSION--, the Pascal-to-C translator *//* From input file "examples/basic.p" */ /*$ debug$*/ #include <p2c/p2c.h> #define checking true #define varnamelen 20#define maxdims 4 typedef Char varnamestring[varnamelen + 1]; typedef Char string255[256]; #define tokvar 0#define toknum 1#define tokstr 2#define toksnerr 3#define tokplus 4#define tokminus 5#define toktimes 6#define tokdiv 7#define tokup 8#define toklp 9#define tokrp 10#define tokcomma 11#define toksemi 12#define tokcolon 13#define tokeq 14#define toklt 15#define tokgt 16#define tokle 17#define tokge 18#define tokne 19#define tokand 20#define tokor 21#define tokxor 22#define tokmod 23#define toknot 24#define toksqr 25#define toksqrt 26#define toksin 27#define tokcos 28#define toktan 29#define tokarctan 30#define toklog 31#define tokexp 32#define tokabs 33#define toksgn 34#define tokstr_ 35#define tokval 36#define tokchr_ 37#define tokasc 38#define toklen 39#define tokmid_ 40#define tokpeek 41#define tokrem 42#define toklet 43#define tokprint 44#define tokinput 45#define tokgoto 46#define tokif 47#define tokend 48#define tokstop 49#define tokfor 50#define toknext 51#define tokwhile 52#define tokwend 53#define tokgosub 54#define tokreturn 55#define tokread 56#define tokdata 57#define tokrestore 58#define tokgotoxy 59#define tokon 60#define tokdim 61#define tokpoke 62#define toklist 63#define tokrun 64#define toknew 65#define tokload 66#define tokmerge 67#define toksave 68#define tokbye 69#define tokdel 70#define tokrenum 71#define tokthen 72#define tokelse 73#define tokto 74#define tokstep 75 typedef double numarray[];typedef Char *strarray[]; #define forloop 0#define whileloop 1#define gosubloop 2 typedef struct tokenrec { struct tokenrec *next; short kind; union { struct varrec *vp; double num; Char *sp; Char snch; } UU;} tokenrec; typedef struct linerec { long num, num2; tokenrec *txt; struct linerec *next;} linerec; typedef struct varrec { varnamestring name; struct varrec *next; long dims[maxdims]; char numdims; boolean stringvar; union { struct { double *arr; double *val, rv; } U0; struct { Char **sarr; Char **sval, *sv; } U1; } UU;} varrec; typedef struct valrec { boolean stringval; union { double val; Char *sval; } UU;} valrec; typedef struct looprec { struct looprec *next; linerec *homeline; tokenrec *hometok; short kind; union { struct { varrec *vp; double max, step; } U0; } UU;} looprec; Static Char *inbuf; Static linerec *linebase;Static varrec *varbase;Static looprec *loopbase; Static long curline;Static linerec *stmtline, *dataline;Static tokenrec *stmttok, *datatok, *buf; Static boolean exitflag; extern long EXCP_LINE; /*$if not checking$ $range off$$end$*/ Static Void restoredata(){ dataline = NULL; datatok = NULL;} Static Void clearloops(){ looprec *l; while (loopbase != NULL) { l = loopbase->next; Free(loopbase); loopbase = l; }} Static long arraysize(v)varrec *v;{ long i, j, FORLIM; if (v->stringvar) j = 4; else j = 8; FORLIM = v->numdims; for (i = 0; i < FORLIM; i++) j *= v->dims[i]; return j;} Static Void clearvar(v)varrec *v;{ if (v->numdims != 0) Free(v->UU.U0.arr); else if (v->stringvar && v->UU.U1.sv != NULL) Free(v->UU.U1.sv); v->numdims = 0; if (v->stringvar) { v->UU.U1.sv = NULL; v->UU.U1.sval = &v->UU.U1.sv; } else { v->UU.U0.rv = 0.0; v->UU.U0.val = &v->UU.U0.rv; }} Static Void clearvars(){ varrec *v; v = varbase; while (v != NULL) { clearvar(v); v = v->next; }} Static Char *numtostr(Result, n)Char *Result;double n;{ string255 s; long i; s[255] = '\0'; if (n != 0 && fabs(n) < 1e-2 || fabs(n) >= 1e12) { sprintf(s, "% .5E", n); i = strlen(s) + 1; s[i-1] = '\0';/* p2c: examples/basic.p, line 237: * Note: Modification of string length may translate incorrectly [146] */ return strcpy(Result, s); } else { sprintf(s, "%30.10f", n); i = strlen(s) + 1; do { i--; } while (s[i-1] == '0'); if (s[i-1] == '.') i--; s[i] = '\0';/* p2c: examples/basic.p, line 248: * Note: Modification of string length may translate incorrectly [146] */ return strcpy(Result, strltrim(s)); }} #define toklength 20 typedef long chset[9]; Static Void parse(inbuf, buf)Char *inbuf;tokenrec **buf;{ long i = 1; long j, k; Char token[toklength + 1]; tokenrec *t; tokenrec *tptr = NULL; varrec *v; Char ch; double n, d, d1; *buf = NULL; do { ch = ' '; while (i <= strlen(inbuf) && ch == ' ') { ch = inbuf[i-1]; i++; } if (ch != ' ') { t = (tokenrec *)Malloc(sizeof(tokenrec)); if (tptr == NULL) *buf = t; else tptr->next = t; tptr = t; t->next = NULL; switch (ch) { case '"': case '\'': t->kind = tokstr; t->UU.sp = (Char *)Malloc(256); t->UU.sp[255] = '\0'; j = 0; while (i <= strlen(inbuf) && inbuf[i-1] != ch) { j++; t->UU.sp[j-1] = inbuf[i-1]; i++; } t->UU.sp[j] = '\0';/* p2c: examples/basic.p, line 415: * Note: Modification of string length may translate incorrectly [146] */ i++; break; case '+': t->kind = tokplus; break; case '-': t->kind = tokminus; break; case '*': t->kind = toktimes; break; case '/': t->kind = tokdiv; break; case '^': t->kind = tokup; break; case '(': case '[': t->kind = toklp; break; case ')': case ']': t->kind = tokrp; break; case ',': t->kind = tokcomma; break; case ';': t->kind = toksemi; break; case ':': t->kind = tokcolon; break; case '?': t->kind = tokprint; break; case '=': t->kind = tokeq; break; case '<': if (i <= strlen(inbuf) && inbuf[i-1] == '=') { t->kind = tokle; i++; } else if (i <= strlen(inbuf) && inbuf[i-1] == '>') { t->kind = tokne; i++; } else t->kind = toklt; break; case '>': if (i <= strlen(inbuf) && inbuf[i-1] == '=') { t->kind = tokge; i++; } else t->kind = tokgt; break; default: if (isalpha(ch)) { i--; j = 0; token[toklength] = '\0'; while (i <= strlen(inbuf) && (inbuf[i-1] == '$' || inbuf[i-1] == '_' || isalnum(inbuf[i-1]))) { if (j < toklength) { j++; token[j-1] = inbuf[i-1]; } i++; } token[j] = '\0';/* p2c: examples/basic.p, line 309: * Note: Modification of string length may translate incorrectly [146] */ if (!strcmp(token, "and") || !strcmp(token, "AND")) t->kind = tokand; else if (!strcmp(token, "or") || !strcmp(token, "OR")) t->kind = tokor; else if (!strcmp(token, "xor") || !strcmp(token, "XOR")) t->kind = tokxor; else if (!strcmp(token, "not") || !strcmp(token, "NOT")) t->kind = toknot; else if (!strcmp(token, "mod") || !strcmp(token, "MOD")) t->kind = tokmod; else if (!strcmp(token, "sqr") || !strcmp(token, "SQR")) t->kind = toksqr; else if (!strcmp(token, "sqrt") || !strcmp(token, "SQRT")) t->kind = toksqrt; else if (!strcmp(token, "sin") || !strcmp(token, "SIN")) t->kind = toksin; else if (!strcmp(token, "cos") || !strcmp(token, "COS")) t->kind = tokcos; else if (!strcmp(token, "tan") || !strcmp(token, "TAN")) t->kind = toktan; else if (!strcmp(token, "arctan") || !strcmp(token, "ARCTAN")) t->kind = tokarctan; else if (!strcmp(token, "log") || !strcmp(token, "LOG")) t->kind = toklog; else if (!strcmp(token, "exp") || !strcmp(token, "EXP")) t->kind = tokexp; else if (!strcmp(token, "abs") || !strcmp(token, "ABS")) t->kind = tokabs; else if (!strcmp(token, "sgn") || !strcmp(token, "SGN")) t->kind = toksgn; else if (!strcmp(token, "str$") || !strcmp(token, "STR$")) t->kind = tokstr_; else if (!strcmp(token, "val") || !strcmp(token, "VAL")) t->kind = tokval; else if (!strcmp(token, "chr$") || !strcmp(token, "CHR$")) t->kind = tokchr_; else if (!strcmp(token, "asc") || !strcmp(token, "ASC")) t->kind = tokasc; else if (!strcmp(token, "len") || !strcmp(token, "LEN")) t->kind = toklen; else if (!strcmp(token, "mid$") || !strcmp(token, "MID$")) t->kind = tokmid_; else if (!strcmp(token, "peek") || !strcmp(token, "PEEK")) t->kind = tokpeek; else if (!strcmp(token, "let") || !strcmp(token, "LET")) t->kind = toklet; else if (!strcmp(token, "print") || !strcmp(token, "PRINT")) t->kind = tokprint; else if (!strcmp(token, "input") || !strcmp(token, "INPUT")) t->kind = tokinput; else if (!strcmp(token, "goto") || !strcmp(token, "GOTO")) t->kind = tokgoto; else if (!strcmp(token, "go to") || !strcmp(token, "GO TO")) t->kind = tokgoto;Lines 1–500 of 2772. Load more
/* Output from p2c --VERSION--, the Pascal-to-C translator */ /* From input file "examples/basic.p" */ /*$ debug$*/ #include <p2c/p2c.h> #define checking true #define varnamelen 20 #define maxdims 4 typedef Char varnamestring[varnamelen + 1]; typedef Char string255[256]; #define tokvar 0 #define toknum 1 #define tokstr 2 #define toksnerr 3 #define tokplus 4 #define tokminus 5 #define toktimes 6 #define tokdiv 7 #define tokup 8 #define toklp 9 #define tokrp 10 #define tokcomma 11 #define toksemi 12 #define tokcolon 13 #define tokeq 14 #define toklt 15 #define tokgt 16 #define tokle 17 #define tokge 18 #define tokne 19 #define tokand 20 #define tokor 21 #define tokxor 22 #define tokmod 23 #define toknot 24 #define toksqr 25 #define toksqrt 26 #define toksin 27 #define tokcos 28 #define toktan 29 #define tokarctan 30 #define toklog 31 #define tokexp 32 #define tokabs 33 #define toksgn 34 #define tokstr_ 35 #define tokval 36 #define tokchr_ 37 #define tokasc 38 #define toklen 39 #define tokmid_ 40 #define tokpeek 41 #define tokrem 42 #define toklet 43 #define tokprint 44 #define tokinput 45 #define tokgoto 46 #define tokif 47 #define tokend 48 #define tokstop 49 #define tokfor 50 #define toknext 51 #define tokwhile 52 #define tokwend 53 #define tokgosub 54 #define tokreturn 55 #define tokread 56 #define tokdata 57 #define tokrestore 58 #define tokgotoxy 59 #define tokon 60 #define tokdim 61 #define tokpoke 62 #define toklist 63 #define tokrun 64 #define toknew 65 #define tokload 66 #define tokmerge 67 #define toksave 68 #define tokbye 69 #define tokdel 70 #define tokrenum 71 #define tokthen 72 #define tokelse 73 #define tokto 74 #define tokstep 75 typedef double numarray[]; typedef Char *strarray[]; #define forloop 0 #define whileloop 1 #define gosubloop 2 typedef struct tokenrec { struct tokenrec *next; short kind; union { struct varrec *vp; double num; Char *sp; Char snch; } UU; } tokenrec; typedef struct linerec { long num, num2; tokenrec *txt; struct linerec *next; } linerec; typedef struct varrec { varnamestring name; struct varrec *next; long dims[maxdims]; char numdims; boolean stringvar; union { struct { double *arr; double *val, rv; } U0; struct { Char **sarr; Char **sval, *sv; } U1; } UU; } varrec; typedef struct valrec { boolean stringval; union { double val; Char *sval; } UU; } valrec; typedef struct looprec { struct looprec *next; linerec *homeline; tokenrec *hometok; short kind; union { struct { varrec *vp; double max, step; } U0; } UU; } looprec; Static Char *inbuf; Static linerec *linebase; Static varrec *varbase; Static looprec *loopbase; Static long curline; Static linerec *stmtline, *dataline; Static tokenrec *stmttok, *datatok, *buf; Static boolean exitflag; extern long EXCP_LINE; /*$if not checking$ $range off$ $end$*/ Static Void restoredata() { dataline = NULL; datatok = NULL; } Static Void clearloops() { looprec *l; while (loopbase != NULL) { l = loopbase->next; Free(loopbase); loopbase = l; } } Static long arraysize(v) varrec *v; { long i, j, FORLIM; if (v->stringvar) j = 4; else j = 8; FORLIM = v->numdims; for (i = 0; i < FORLIM; i++) j *= v->dims[i]; return j; } Static Void clearvar(v) varrec *v; { if (v->numdims != 0) Free(v->UU.U0.arr); else if (v->stringvar && v->UU.U1.sv != NULL) Free(v->UU.U1.sv); v->numdims = 0; if (v->stringvar) { v->UU.U1.sv = NULL; v->UU.U1.sval = &v->UU.U1.sv; } else { v->UU.U0.rv = 0.0; v->UU.U0.val = &v->UU.U0.rv; } } Static Void clearvars() { varrec *v; v = varbase; while (v != NULL) { clearvar(v); v = v->next; } } Static Char *numtostr(Result, n) Char *Result; double n; { string255 s; long i; s[255] = '\0'; if (n != 0 && fabs(n) < 1e-2 || fabs(n) >= 1e12) { sprintf(s, "% .5E", n); i = strlen(s) + 1; s[i-1] = '\0'; /* p2c: examples/basic.p, line 237: * Note: Modification of string length may translate incorrectly [146] */ return strcpy(Result, s); } else { sprintf(s, "%30.10f", n); i = strlen(s) + 1; do { i--; } while (s[i-1] == '0'); if (s[i-1] == '.') i--; s[i] = '\0'; /* p2c: examples/basic.p, line 248: * Note: Modification of string length may translate incorrectly [146] */ return strcpy(Result, strltrim(s)); } } #define toklength 20 typedef long chset[9]; Static Void parse(inbuf, buf) Char *inbuf; tokenrec **buf; { long i = 1; long j, k; Char token[toklength + 1]; tokenrec *t; tokenrec *tptr = NULL; varrec *v; Char ch; double n, d, d1; *buf = NULL; do { ch = ' '; while (i <= strlen(inbuf) && ch == ' ') { ch = inbuf[i-1]; i++; } if (ch != ' ') { t = (tokenrec *)Malloc(sizeof(tokenrec)); if (tptr == NULL) *buf = t; else tptr->next = t; tptr = t; t->next = NULL; switch (ch) { case '"': case '\'': t->kind = tokstr; t->UU.sp = (Char *)Malloc(256); t->UU.sp[255] = '\0'; j = 0; while (i <= strlen(inbuf) && inbuf[i-1] != ch) { j++; t->UU.sp[j-1] = inbuf[i-1]; i++; } t->UU.sp[j] = '\0'; /* p2c: examples/basic.p, line 415: * Note: Modification of string length may translate incorrectly [146] */ i++; break; case '+': t->kind = tokplus; break; case '-': t->kind = tokminus; break; case '*': t->kind = toktimes; break; case '/': t->kind = tokdiv; break; case '^': t->kind = tokup; break; case '(': case '[': t->kind = toklp; break; case ')': case ']': t->kind = tokrp; break; case ',': t->kind = tokcomma; break; case ';': t->kind = toksemi; break; case ':': t->kind = tokcolon; break; case '?': t->kind = tokprint; break; case '=': t->kind = tokeq; break; case '<': if (i <= strlen(inbuf) && inbuf[i-1] == '=') { t->kind = tokle; i++; } else if (i <= strlen(inbuf) && inbuf[i-1] == '>') { t->kind = tokne; i++; } else t->kind = toklt; break; case '>': if (i <= strlen(inbuf) && inbuf[i-1] == '=') { t->kind = tokge; i++; } else t->kind = tokgt; break; default: if (isalpha(ch)) { i--; j = 0; token[toklength] = '\0'; while (i <= strlen(inbuf) && (inbuf[i-1] == '$' || inbuf[i-1] == '_' || isalnum(inbuf[i-1]))) { if (j < toklength) { j++; token[j-1] = inbuf[i-1]; } i++; } token[j] = '\0'; /* p2c: examples/basic.p, line 309: * Note: Modification of string length may translate incorrectly [146] */ if (!strcmp(token, "and") || !strcmp(token, "AND")) t->kind = tokand; else if (!strcmp(token, "or") || !strcmp(token, "OR")) t->kind = tokor; else if (!strcmp(token, "xor") || !strcmp(token, "XOR")) t->kind = tokxor; else if (!strcmp(token, "not") || !strcmp(token, "NOT")) t->kind = toknot; else if (!strcmp(token, "mod") || !strcmp(token, "MOD")) t->kind = tokmod; else if (!strcmp(token, "sqr") || !strcmp(token, "SQR")) t->kind = toksqr; else if (!strcmp(token, "sqrt") || !strcmp(token, "SQRT")) t->kind = toksqrt; else if (!strcmp(token, "sin") || !strcmp(token, "SIN")) t->kind = toksin; else if (!strcmp(token, "cos") || !strcmp(token, "COS")) t->kind = tokcos; else if (!strcmp(token, "tan") || !strcmp(token, "TAN")) t->kind = toktan; else if (!strcmp(token, "arctan") || !strcmp(token, "ARCTAN")) t->kind = tokarctan; else if (!strcmp(token, "log") || !strcmp(token, "LOG")) t->kind = toklog; else if (!strcmp(token, "exp") || !strcmp(token, "EXP")) t->kind = tokexp; else if (!strcmp(token, "abs") || !strcmp(token, "ABS")) t->kind = tokabs; else if (!strcmp(token, "sgn") || !strcmp(token, "SGN")) t->kind = toksgn; else if (!strcmp(token, "str$") || !strcmp(token, "STR$")) t->kind = tokstr_; else if (!strcmp(token, "val") || !strcmp(token, "VAL")) t->kind = tokval; else if (!strcmp(token, "chr$") || !strcmp(token, "CHR$")) t->kind = tokchr_; else if (!strcmp(token, "asc") || !strcmp(token, "ASC")) t->kind = tokasc; else if (!strcmp(token, "len") || !strcmp(token, "LEN")) t->kind = toklen; else if (!strcmp(token, "mid$") || !strcmp(token, "MID$")) t->kind = tokmid_; else if (!strcmp(token, "peek") || !strcmp(token, "PEEK")) t->kind = tokpeek; else if (!strcmp(token, "let") || !strcmp(token, "LET")) t->kind = toklet; else if (!strcmp(token, "print") || !strcmp(token, "PRINT")) t->kind = tokprint; else if (!strcmp(token, "input") || !strcmp(token, "INPUT")) t->kind = tokinput; else if (!strcmp(token, "goto") || !strcmp(token, "GOTO")) t->kind = tokgoto; else if (!strcmp(token, "go to") || !strcmp(token, "GO TO")) t->kind = tokgoto;