void Lexer::getNextToken() { switch (this->currentChar) { case '0' ... '9': recognizeNumber(); break; case 'a' ... 'z': case 'A' ... 'Z': recognizeIdentifier(); break; case '#': eatComments(); break; case '<': case '>': case '/': case '*': case '+': case '-': case '%': case '^': case '$': case '!': case '=': case '|': case '?': case '~': case ':': case ';': case '\\': case '.': case '&': recognizeOperator(); break; case '\'': recognizeCharacter(); break; case '"': recognizeString(); break; case '[': case ']': case '(': case ')': case '{': case '}': case ',': recognizeSeparator(); break; case '\0': // eof this->running = false; break; case ' ': case '\t': case '\n': case '\r': this->pos++; this->currentChar = this->file->contents[this->pos]; break; default: std::cout << "WHAT YEAR IS IT (" << this->currentChar << ")" << std::endl; break; } }
/* the header looks like this: *--------- * P6 * # comments if you want to * width height * 255 *--------- * then follows RGBRGBRGBRGBRGB... */ struct Texture *viReadPPM(char *filename) { FILE *f; char ch; int width, height, colres; if(f=fopen(filename,"rb")) { char str[100]; struct Texture *tx; eatWhitespace(f); eatComments(f); eatWhitespace(f); fscanf(f,"%s",str); if(strcmp(str,"P6")!=0) { printf("Error: the texture image file must be of raw color PPM format,\n"); printf("i.e., it must have P6 in the header. File: %s\n",filename); exit(1); } eatWhitespace(f); eatComments(f); eatWhitespace(f); fscanf(f,"%d %d",&width,&height); if(width<=0 || height<=0) { printf("Error: width and height of the image must be greater than zero. File: %s\n",filename); exit(1); } eatWhitespace(f); eatComments(f); eatWhitespace(f); fscanf(f,"%d",&colres); if(colres!=255) { printf("Error: color resolution must be 255.File: %s\n",filename); return NULL; } /* gotta eat the newline too */ ch=0; while(ch!='\n') fscanf(f,"%c",&ch); tx=(struct Texture*)malloc(sizeof(struct Texture)); if(tx==NULL) { printf("Error: could not allocate memory for texture struct. File: %s\n",filename); return NULL; } tx->mWidth=width; tx->mHeight=height; tx->mRGB=(unsigned char*)malloc(3*width*height); if(tx->mRGB==NULL) { printf("Error: could not allocate memory for the pixels of the texture. File: %s\n",filename); exit(1); } if(fread(tx->mRGB,3*width*height,1,f)!=1) { printf("Error: could not read 3 x %d bytes of pixel info. File: %s\n",width*height,filename); return NULL; } fclose(f); return tx; } else { printf("Error: could not open %s.\n",filename); return NULL; } }
void plexser::tokenize() { dbg::trace tr("plexser", DBG_HERE); char current; input->seekg(0); lineNum = 1; columnNum = 1; current = getChar(); while(!input->eof()) { //std::cout << "HERE" << std::endl; //std::cout << current << std::endl; if(isspace(current)) { eatWhiteSpace(); } else if(current == '/' && (input->peek() == '/' || input->peek() == '*')) { eatComments(); } else if(state == plexser::skiptogen) { NonGenerated(current); } else if(state == plexser::funcheader) { input->unget(); std::streampos pos = input->tellg(); input->get(); std::pair<std::string, char> current_token = nextToken(current); current = getChar(); if(current_token.first == "using") { // create namespace and class object std::string ns_and_class = nextToken(current).first; std::string::size_type pos = ns_and_class.find("::", 0); if(pos != std::string::npos) { std::string ns = ns_and_class.substr(0, pos); std::string cls = ns_and_class.substr(ns.size()+2, ns_and_class.size()); cppnamespace nspace(ns); getClass(cls).setNamespace(nspace); } } else { input->seekg(pos); //std::cout << "Peek: " << input->peek() << std::endl; buildFuncHeader(current, current_token); } } current = getChar(); } postProcess(); }