1. What happened to the translator?
- Posted by mtsreborn at yahoo.com Feb 26, 2001
- 431 views
What the? What's up with the translator? It's got more bugs than an african baby... It used to be stable, and look at it now! It's all cookoo! Damn Robby rob rob rob! What happened? Did you fall asleap while you were coding? Hehe, oh BTW, what did you tink of that MP3 I sent you? Pretty funny wasn't it? Put it on the RDS site, as a user contribution, shows people you have a sense of humour :p Anyways, I gave up hope on Euphoria, and you should to. There are more powerfull tools out there to code your apps. C ain't bad, it won't kill ya. And wait untill NightShade is complete. What is that? Think it's vapor ware? HAHA! Yeah right... Here's my code, with two sections, wich would give away the store, commented out; /* NightShade */ /* Native Interpreter with Garbage-collected */ /* Hierarchical Threads in Syntactical Human */ /* Alphabetics for Direct Execution */ /* Version 1.0 */ /* By Mike The Spike */ /* Standard include files */ #include <stdio.h> #include <string.h> #include <stdlib.h> #include <malloc.h> #include <math.h> #include <ctype.h> /* Types */ typedef struct { char **toks; int length; } tokens; typedef void (*Verb)(); /* Verbs */ /* STRIPPED FOR SECURITY REASONS */ /* Globals */ /* STRIPPED FOR SECURITY REASONS */ /* Function Defines */ void *ns_malloc(int size) { void *ret; if((ret = malloc(size)) == 0) { puts("This program ran out of memory...\n"); exit(1); } else return ret; return ret; } void *ns_realloc(void *mem,int nsize) { void *ret; if((ret = realloc(mem,nsize)) == 0) { puts("This program ran out of memory...\n"); exit(1); } else return ret; return ret; } char *makestring(char what) { /* Make a string from single-character 'what'. eg. 'h' becomes "h" */ char *ret; ret = " "; ret[0] = what; return ret; } tokens parse(char *what) { /* Parse string 'what' and return result */ char *currtok; tokens ret; char *s = what; ret.length = 0; ret.toks = (char**)ns_malloc(sizeof(char*)); while(1) { currtok = strtok(s," \t\n"); if(currtok == NULL) break; ret.toks = ret.toks[ret.length] = currtok; ret.length++; s = NULL; } return ret; } void killtoks(tokens which) { /* Kill them all!!!! YAAAEERRGHHH!!! */ int i; for(i = 0; i < which.length; i++) free(which.toks[i]); free(which.toks); } int has_ending(char *what) { /* Does 'what' contain any sentance deliminators? (!?.;:) */ int i; for(i = 0; i < strlen(what);i++) { if(what[i] == '.' || what[i] == '!' || what[i] == '?') if(!isdigit(what[i+1])) return what[i]; } return 0; } int match_ncase(char *a, char *b) { /* Case Insensitive Comparision */ int i; for(i = 0; i < strlen(a); i++) a[i] = tolower(a[i]); for(i = 0; i < strlen(b); i++) b[i] = tolower(b[i]); return strcmp(a,b); } int find(tokens where, char *what, int delim) { /* Search for 'what' as part of 'where' but ignore 'delim' (can be -1) */ int i; for(i = 0; i < where.length;i++) if(strcmp(where.toks[i],what) == 0) if(i != delim) return 1; return 0; } char * file_to_string(char * path) { /* Turn file 'path' into a string */ FILE *fptr; char *ret; int c; c = 0; fptr = fopen(path,"r"); if(fptr == NULL) return NULL; /* Get the size of the file */ while(!feof(fptr)) { fgetc(fptr); c++; } /* Reset file pointer to 0 */ fseek(fptr,0,0); /* Read in entire file */ ret = (char*)ns_malloc(c); fread(ret,1,c,fptr); /* Close file */ fclose(fptr); /* Return it */ return ret; } tokens append_unique(tokens dest, tokens what) { /* Append contents of 'what' to 'dest' */ int i,c; dest.toks = c = 0; for(i = dest.length; i < dest.length+what.length;i++) { /* Below evaluation to resolve duplicate appends */ dest.toks[i] = what.toks[i-dest.length]; else { dest.toks[i] = "NS_MTS_DELMEIMFAKE"; c++; } } dest.length+=what.length; /* Get rid of all marked tokens */ return dest; } tokens append(tokens dest, tokens what) { /* Append contents of 'what' to 'dest' */ int i; dest.toks = for(i = dest.length; i < dest.length+what.length;i++) dest.toks[i] = what.toks[i-dest.length]; dest.length+=what.length; return dest; } tokens get_includes(tokens where) { /* Get included filenames from tokenised string 'where' */ tokens ret; int i; ret.length = 0; ret.toks = (char**)ns_malloc(sizeof(char*)); for(i = 0; i < where.length; i++) { if(match_ncase(where.toks[i],"include") == 0) if(i == where.length-1) { puts("An error was found in your program."); puts("Error: Expected to see an include file,"); puts("not the end of file!"); puts(">> include <end-of-file> ..."); killtoks(ret); exit(0); } else { ret.toks[ret.length] = where.toks[i+1]; ret.length++; ret.toks = } } return ret; } tokens get_all_includes(tokens where) { /* Get -all- included filenames from tokenised string 'where' */ tokens ret, temp; int cnt; FILE *fptr; char *foo; cnt = 0; ret.length = 0; if(where.length == 0) return ret; ret = get_includes(where); if(ret.length == 0) return ret; while(1) { if(strcmp(ret.toks[cnt],"NS_MTS_DELMEIMFAKE") != 0) { foo = file_to_string(ret.toks[cnt]); if(foo == NULL) { printf("Can't include %s ...\n",ret.toks[cnt]); exit(0); } temp = parse(foo); temp = get_includes(temp); ret = append_unique(ret,temp); free(foo); } cnt++; if(cnt == ret.length) break; } return ret; } void interpret(char *what) { /* Compile program 'what' to memory and run it immediatly */ tokens *progs; tokens temp; int i,ix,pcount; temp = parse(what); temp = get_all_includes(temp); pcount = 0; progs = (tokens*)ns_malloc(sizeof(tokens)*temp.length); for(i = 0;i < temp.length;i++) { if(strcmp(temp.toks[i],"NS_MTS_DELMEIMFAKE") != 0) { progs[i] = parse(file_to_string(temp.toks[i])); pcount++; } } /* Interpret all */ for(i = 0; i < pcount; i++) for(ix = 0; ix < progs[i].length;ix++) { /* STRIPPED FOR SECURITTY REASONS */ } } main() { interpret("include test.txt"); } Above code is useless for you, I stripped out the sensitive portions, but it is compilable. Try it, run it and get an approriate error message. There is a routine called 'translate' wich I haven't coded yet. It translates to C, but it's almost the same as interpret(). Wait for this puppy, it will let you code in English, and code cool games and stuff. If only Rob would hurry up with Euphoria... You wouldn't need this product... Mike The Spike
2. Re: What happened to the translator?
- Posted by codehead78 at YAHOO.COM Feb 26, 2001
- 422 views
--- mtsreborn at yahoo.com wrote: <hack> > Anyways, I gave up hope on Euphoria, and you should > to. > There are more powerfull tools out there to code > your > apps. I plan to use it for testing algorithms I will later write in C or C++. I would rather write my own than have the overhead of Euphoria types. But if the translator becomes smart enough, it might recognize the restrictions imposed on types and create the appropriate type in C. If Rob put out some standard types the the translator could easily understand it wouldn't be so difficult. <chop> > Here's my code, with two sections, wich would give > away the store, commented out; > > /* NightShade */ > /* Native Interpreter with Garbage-collected */ > /* Hierarchical Threads in Syntactical Human */ > /* Alphabetics for Direct Execution */ > /* Version 1.0 */ > > /* By Mike The Spike */ > .. /* Function Defines */ void *ns_malloc(int size) { void *ret; if((ret = malloc(size)) == 0) { puts("This program ran out of memory... "); exit(1); } // You don't need this... // else // return ret; return ret; } Just nit picking... Good luck, -Humberto
3. Re: What happened to the translator?
- Posted by mtsreborn at yahoo.com Feb 27, 2001
- 416 views
--- codehead78 at YAHOO.COM wrote: > --- mtsreborn at yahoo.com wrote: > <hack> > > > Anyways, I gave up hope on Euphoria, and you > should > > to. > > There are more powerfull tools out there to code > > your > > apps. > I plan to use it for testing algorithms I will later > write in C or C++. I would rather write my own than > have the overhead of Euphoria types. But if the > translator becomes smart enough, it might recognize > the restrictions imposed on types and create the > appropriate type in C. If Rob put out some standard > types the the translator could easily understand it > wouldn't be so difficult. Same here ma man... > <chop> > > > Here's my code, with two sections, wich would give > > away the store, commented out; > > > > /* NightShade */ > > /* Native Interpreter with Garbage-collected */ > > /* Hierarchical Threads in Syntactical Human */ > > /* Alphabetics for Direct Execution */ > > /* Version 1.0 */ > > > > /* By Mike The Spike */ > > > > ... > > /* Function Defines */ > void *ns_malloc(int size) > { > void *ret; > if((ret = malloc(size)) == 0) > { > puts("This program ran out of memory... > "); > exit(1); > } > // You don't need this... > // else > // return ret; > > > return ret; > } > > Just nit picking... > > Good luck, > -Humberto I know... I like, code this malloc/realloc wrapper 20 times a day :p Sometimes I just hurry up and do it wrongly. This is what I rewrote it to now; void *ns_malloc(int size) { void *ret; if((ret = malloc(size)) == 0) { puts("This program ran out of memory..."); exit(0); } return ret; } But it's more like potatoes/tomatoes (huh???), no biggy. Mike The Spike