/* Returns index if a sentence matches, 0 otherwise */ int method(int index) { if(tokens[(index = readTok(index))] == VOID_METHOD_START) { if(tokens[(index = readTok(index))] == OPENTOK) { if(index = contents(index)) { if(tokens[(index = readTok(index))] == CLOSETOK) return index; } } } if(nextTok(index) == METHOD_START) { if(nextTok(index) == OPENTOK) { if(index = contents(index)) { if(nextTok(index) == CLOSETOK) return index; } } } return index; }
/* Returns index if a sentence matches, 0 otherwise */ int default_(int index) { if(nextTok(index) == DEFAULT_START) { if(nextTok(index) == RETURN) return index; pushBack(index); } pushBack(index); return 0; }
/* Returns 1 if a sentence matches, 0 otherwise */ int if_(int index) { if(nextTok(index) == IF_START) { if(nextTok(index) == OPENTOK) { if(index = contents(index)) { if(nextTok(index)==CLOSETOK) return index; } } } return 0; }
static int at_tok_nextint_base(char **p_cur, int *p_out, int base, int uns) { char *ret; if (*p_cur == NULL) { return -1; } ret = nextTok(p_cur); if (ret == NULL) { return -1; } else { long l; char *end; if (uns) l = strtoul(ret, &end, base); else l = strtol(ret, &end, base); *p_out = (int)l; if (end == ret) { return -1; } } return 0; }
/* Returns index if a sentence matches, 0 otherwise */ int else_(int index) { if(nextTok(index) == ELSE_START) { if(nextTok(index)==OPENTOK) { if(index = contents(index)) { if(nextTok(index)==CLOSETOK) return index; } } return 0; } index = pushBack(index); return index; }
/* Returns index if a sentence matches, 0 otherwise */ int switch_(int index) { if(nextTok(index) == SWITCH_START) { if(nextTok(index)==OPENTOK) { if(index = cases(index)) { if(index = default_(index)) { if(nextTok(index) == CLOSETOK) return index; } } } } return 0; }
token_t nexTok() { if(buffer == NULL) { perror("Trying to call nexTok, but buffer is null!"); return (token_t){-1,-1,NULL}; } return nextTok(buffer); }
/* Returns index if a sentence matches, 0 otherwise */ int cases(int index) { if(nextTok(index) == CASE) { if(index = cases(index)) return index; } index = pushBack(index); return index; }
/* Returns index if a sentence matches, 0 otherwise */ int elseif_(int index) { if(nextTok(index) == ELSEIF_START) { if(nextTok(index) == OPENTOK) { if(index = contents(index)) { if(nextTok(index)==CLOSETOK) return index; } } index = pushBack(index); return 0; } /* I have a feeling this line needs to be in more places */ index = pushBack(index); return index; }
int at_tok_nextstr(char **p_cur, char **p_out) { if (*p_cur == NULL) { return -1; } *p_out = nextTok(p_cur); return 0; }
token_t nextTok(buffer_t *buffer) { //printf(" %i | %i",buffer->offset+1, buffer->size); if(buffer->offset+1 >= buffer->size) //+1 needed because offset wont save EOF { return (token_t){-1,-1,NULL}; } token_t token = {-1,-1, NULL}; int lexeme_length = 0; int state = 0; int prevState = 0; char transition = 0; rmWhites(&buffer); do { prevState = state; //protect from buffer over-offseting, for example by never ending string if((buffer->advance+1 >= buffer->size) ) { buffer->advance++; break; } transition = charToType(buffer->buf[buffer->advance++]); state = tranMat[state][transition]; buffer->charNum++; }while(state != AC && state != ER); buffer->charNum--; //remove lookahead //setup the token buffer->advance--; lexeme_length = buffer->advance - buffer->offset ; token.lexeme = malloc((sizeof(char)) * (lexeme_length + 1)); strncpy(token.lexeme,&((buffer->buf)[buffer->offset]), lexeme_length); token.lexeme[lexeme_length] = '\0'; buffer->offset = buffer->advance; //classify token category and type switch(prevState) { case 1: token.type = AND; token.category = OP_LOG_BIN; break; case 2: token.type = OR; token.category = OP_LOG_BIN; break; // case 4: token.type = RA; token.category = OP_LOG_BIN; break; case 5: token.type = LA; token.category = OP_LOG_BIN; break; case 6: token.type = LT; token.category = REL_OP; break; // case 8: token.type = DA; token.category = OP_LOG_BIN;break; case 9: token.type = UNIVERSAL;break; case 10: token.type = EXISTENTIAL;break; case 11: token.type = EQ; token.category = REL_OP; break; // case 13: token.type = DIFF; token.category = REL_OP; break; // case 15: token.type = GT; token.category = REL_OP; break; case 16: token.type = LTE; token.category = REL_OP; break; case 17: token.type = GTE; token.category = REL_OP; break; case 18: token.type = VAR;break; case 19: token.type = OBJ_FUNC;break; case 20: token.type = LP;break; case 21: token.type = RP;break; case 22: token.type = NEG;break; //error states case 3: printf("ERROR invalid token -");exit(0); case 7: printf("ERROR invalid state 7");exit(0); case 14: printf("ERROR invalid state 14");exit(0); default: printf(" This symbol is not part of the language: %s\n",token.lexeme); } if(state == ER){ return (token_t){-1,-1,token.lexeme}; } //DONT RETURN TOKEN COMMENTS! maybe something can be done with these here..write to a file for a "javadoc" type of crap if(token.category == CMNT) { free(token.lexeme); return nextTok(buffer); } else return token; }
void parseMasterList(void) { char *tok=inM(); numLibs=numProgs=0; /*Parse LIBS section*/ if (tokNot("LIBS")) wrong("Expected LIBS, got ",tok); nextTok(); if (tokNot("{")) wrong("Expected {, got",tok); nextTokN(); while (tokNot("}")) { lib *l=(lib *)malloc(sizeof(lib)); strcpy(l->path,codeLoc); strcpy(l->name,tok); libs[numLibs++]=l; nextTokN(); } nextTok(); /*Parse PROGRAMS section*/ if (tokNot("PROGRAMS")) wrong("Expected PROGRAMS, got ",tok); nextTok(); if (tokNot("{")) wrong("Expected {, got ",tok); nextTokN(); while (tokNot("}")) { prog *p=(prog *)malloc(sizeof(prog)); strcpy(p->path,codeLoc); strcpy(p->name,tok); p->numLibs=p->numProgs=p->isOnlyBinary=p->isCat=p->isDoc=0; progs[numProgs++]=p; nextTok(); if (tokNot("{")) wrong("Expected {, got ",tok); nextTok(); if (tokIs("PROGRAMS")) { /*We have a program list-- parse it.*/ nextTokN(); while (tokNot("}")&&tokNot("BINS")) { int progNo,oldNumProgs=p->numProgs; for (progNo=0;progNo<numProgs;progNo++) if (0==strcmp(tok,progs[progNo]->name)) p->progs[p->numProgs++]=(PROG *)progs[progNo]; if (oldNumProgs==p->numProgs) /*We couldn't find the referenced program.*/ printf("SEVERE WARNING: couldn't find program '%s',\n" " part of program '%s'! Ignoring...\n\n",tok,p->name); nextTokN(); } } if (tokIs("BINS")) { /*We have a "directory-less binaries" list-- parse it.*/ nextTokN(); while (tokNot("}")) { prog *q; /*q will be a directory-less binary for program p*/ q=(prog *)malloc(sizeof(prog)); p->progs[p->numProgs++]=(PROG *)q; strcpy(q->path,codeLoc);/*Same path.*/ strcpy(q->name,tok);/*New name.*/ q->numLibs=q->numProgs=0;/*No subprograms.*/ q->isOnlyBinary=1; nextTokN(); } } if (tokIs("}")) nextTokN() else wrong("Expected } to close PROGRAM, got ",tok); } nextTok(); /*Parse DOCUMENTATION section*/ if (tokNot("DOCUMENTATION")) wrong("Expected DOCUMENTATION, got ",tok); nextTok(); if (tokNot("{")) wrong("Expected {, got",tok); nextTokN(); while (tokNot("}")) { prog *p=(prog *)malloc(sizeof(prog)); strcpy(p->path,codeLoc); strcpy(p->name,tok); p->numLibs=p->numProgs=p->isOnlyBinary=p->isCat=0; p->isDoc=1; progs[numProgs++]=p; nextTokN(); } nextTok(); /*Parse CATEGORIES section*/ if (tokNot("CATEGORIES")) wrong("Expected CATEGORIES, got ",tok); nextTok(); if (tokNot("{")) wrong("Expected {, got ",tok); nextTokN(); while (tokNot("}")) { prog *p=(prog *)malloc(sizeof(prog)); strcpy(p->path,"CATEGORY/"); strcpy(p->name,tok); p->numProgs=p->numLibs=p->isOnlyBinary=p->isDoc=0; p->isCat=1; progs[numProgs++]=p; nextTok(); if (tokNot("{")) wrong("Expected {, got ",tok); nextTok(); while (tokNot("}")) { int progNo,oldNumProgs=p->numProgs; for (progNo=0;progNo<numProgs;progNo++) if (0==strcmp(tok,progs[progNo]->name)) p->progs[p->numProgs++]=(PROG *)progs[progNo]; if (oldNumProgs==p->numProgs) /*We couldn't find the referenced program.*/ printf("WARNING: couldn't find '%s',\n" " a part of the '%s' package! Ignoring...\n\n",tok,p->name); nextTokN(); } if (tokIs("}")) nextTokN() else wrong("Expected } to close CATEGORIES, got ",tok); } }
cGameCell::cGameCell( cFile& file, int num ) : m_index( num ) { queue<string> tokQueue; SetID( MakeID( c_cellSegment, num ) ); MsgDaemon()->RegObject( GetID(), this ); string tok; do { file.TokenizeNextNCLine( &tokQueue, '#' ); tok = nextTok( tokQueue ); if( tok == "CELL_START" ) { // do nothing } else if( tok == "CELL_END" ) { break; } else if( tok == "PT" ) { point3 pt; // Read in the point tok = nextTok( tokQueue ); pt.x = atof( tok.c_str() ); tok = nextTok( tokQueue ); pt.y = atof( tok.c_str() ); tok = nextTok( tokQueue ); pt.z = atof( tok.c_str() ); // Append it to the list m_ptList.push_back( pt ); } else if( tok == "FACE" ) { tok = nextTok( tokQueue ); int nInd = atoi( tok.c_str() ); // Create the polygon structure to fill sPolygon currPoly; currPoly.m_nVerts = nInd; /** * The next line is the indices. */ file.TokenizeNextNCLine( &tokQueue, '#' ); // Fill in the indices for( int i=0; i< nInd; i++ ) { tok = nextTok( tokQueue ); currPoly.m_vList[i].m_ind = atoi( tok.c_str() ); } // Now we can build the plane. currPoly.m_plane = plane3( m_ptList[currPoly.m_vList[0].m_ind], m_ptList[currPoly.m_vList[1].m_ind], m_ptList[currPoly.m_vList[2].m_ind] ); /** * Next line is the colors */ file.TokenizeNextNCLine( &tokQueue, '#' ); // Fill in the colors for( i=0; i< nInd; i++ ) { tok = nextTok( tokQueue ); sscanf( tok.c_str(), "%x", &currPoly.m_vList[i].m_col ); } /** * Final line is the texture info. */ file.TokenizeNextNCLine( &tokQueue, '#' ); point3 m, n, p; // First token says whether to auto generate textures // Or explicitly read them. tok = nextTok( tokQueue ); if( tok == "AUTO" ) { // Automatically generate the texture vectors p = (m_ptList[currPoly.m_vList[0].m_ind]); tok = nextTok( tokQueue ); currPoly.m_texID = atoi( tok.c_str() ); tok = nextTok( tokQueue ); float mScale = atof( tok.c_str() ); tok = nextTok( tokQueue ); float nScale = atof( tok.c_str() ); // Run tests to figure out which way the plane faces if( point3::i == currPoly.m_plane.n || -1*point3::i == currPoly.m_plane.n ) { // plane points in the +/-x direction m.Assign(0,0,1); n.Assign(0,1,0); } else if( point3::j == currPoly.m_plane.n || -1*point3::j == currPoly.m_plane.n ) { // plane points in the +/-y direction m.Assign(0,0,1); n.Assign(1,0,0); } else if( point3::k == currPoly.m_plane.n || -1*point3::k == currPoly.m_plane.n ) { // plane points in the +/-z direction m.Assign(1,0,0); n.Assign(0,1,0); } // No easy guess... just estimate using the first two points as one vector // and the cross as the other. else { m = m_ptList[currPoly.m_vList[1].m_ind] - m_ptList[currPoly.m_vList[0].m_ind]; m.Normalize(); n = m ^ currPoly.m_plane.n; } // scale the vectors by the provided scaling values. m *= mScale; n *= nScale; } else if( tok == "EXP" ) { // Explicit tex-gen. texture ID and then 9 floats (p,m,n). tok = nextTok( tokQueue ); currPoly.m_texID = atoi( tok.c_str() ); // P tok = nextTok( tokQueue ); p.x = atof( tok.c_str() ); tok = nextTok( tokQueue ); p.y = atof( tok.c_str() ); tok = nextTok( tokQueue ); p.z = atof( tok.c_str() ); // M tok = nextTok( tokQueue ); m.x = atof( tok.c_str() ); tok = nextTok( tokQueue ); m.y = atof( tok.c_str() ); tok = nextTok( tokQueue ); m.z = atof( tok.c_str() ); // N tok = nextTok( tokQueue ); n.x = atof( tok.c_str() ); tok = nextTok( tokQueue ); n.y = atof( tok.c_str() ); tok = nextTok( tokQueue ); n.z = atof( tok.c_str() ); } else throw cGameError( "Bad texture gen token" ); float mMag = m.Mag(); m /= mMag; float nMag = n.Mag(); n /= nMag; // We have the n,m,p vectors; let's generate the coordinates. for( i=0; i<nInd; i++ ) { point3 pt = m_ptList[currPoly.m_vList[i].m_ind] - p; float u = (pt * m); float v = (pt * n); currPoly.m_vList[i].m_u = u / mMag; currPoly.m_vList[i].m_v = v / nMag; } // Add the poly m_polyList.push_back( currPoly ); } else if( 0 == tok.compare( "PORTAL" ) ) { tok = nextTok( tokQueue ); int other = atoi( tok.c_str() ); tok = nextTok( tokQueue ); int nInd = atoi( tok.c_str() ); // Create the polygon structure to fill sPortal currPortal; currPortal.m_nVerts = nInd; // first # in the file is 1, here is 0 currPortal.m_other = MakeID( c_cellSegment, other - 1); // Fill in the indices for( int i=0; i< nInd; i++ ) { tok = nextTok( tokQueue ); currPortal.m_vList[i].m_ind = atoi( tok.c_str() ); } currPortal.m_plane = plane3( m_ptList[currPortal.m_vList[0].m_ind], m_ptList[currPortal.m_vList[1].m_ind], m_ptList[currPortal.m_vList[2].m_ind] ); // build the edge planes for this portal currPortal.CalcEdgePlanes( this ); // Add the poly m_portalList.push_back( currPortal ); } } while( 1 ); }