bool lemmatiseFile(const char * OneWordPerLineFile,const char * rulefile,const char * resultFile) { buffer Buffer; if(!readRules(rulefile,&Buffer)) return false; FILE * OWPLF = fopen(OneWordPerLineFile,"rb"); ++openfiles; if(!OWPLF) { deleteRules(); return false; } FILE * rf = fopen(resultFile,"wb"); ++openfiles; if(!rf) { --openfiles; fclose(OWPLF); deleteRules(); return false; } fseek(OWPLF, 0, SEEK_END); long wend = ftell(OWPLF); fseek(OWPLF, 0, SEEK_SET); char * wbuf = new char[(size_t)(wend + 1)]; if (wbuf && wend > 0) { if (fread(wbuf, 1, (size_t)wend, OWPLF) != (size_t)wend) return 0; wbuf[wend] = '\0'; } char * q; for(char * p = wbuf;(q = strchr(p,'\n')) != 0;p = q + 1) { *q = 0; for(char * r = q - 1;r >= p && (*r == '\r' || *r == ' ' || *r == '\t');--r) *r = 0; fprintf(rf,"%s\n",applyRules(p,&Buffer)); } delete [] wbuf; deleteRules(); --openfiles; fclose(rf); --openfiles; fclose(OWPLF); return true; }
bool readRules(const char * filename,buffer * Buffer) { FILE * f = fopen(filename,"rb"); ++openfiles; if(f) { bool result = readRules(f,Buffer); --openfiles; fclose(f); return result; } return false; }
rules(const char * TagName) { this->TagName = new char[strlen(TagName)+1]; strcpy(this->TagName,TagName); char * filename = new char[strlen(TagName)+strlen(flexFileName)+2]; sprintf(filename,"%s.%s",flexFileName,TagName); FILE * f = fopen(filename,"rb"); if(f) { Buf = readRules(f, End); fclose(f); } else { Buf = 0; End = 0; } }
int main() { //generate_table(); //count = get_tokens(); //int j=0,i; int i=0,j; memset(Stack,'0',sizeof(Stack)); // for(i=0;i<300;i++) // memset(Rules[i],0,sizeof(Rules[i])); //char temp[200][30]; //char temp[200][30]; //for(i=0;i<200;i++) // memset(temp[i],'\0',sizeof(temp[i])); //for(i=100;i<127;i++) // j=fill_line(temp,127); //printf("%d",hash_nonterm("variables")); //j=fill_line(temp,108); // j=fill_line(temp,109); // for(i=100;i<128;i++) //j=fill_line(temp,i); int x,y; int count=get_tokens(); for(i=0;i<count;i++) { hashedTokens[i]=hash_tokens(Tokens[i]); // printf("%s %d\n",Tokens[i],hashedTokens[i]); } fout=fopen("Checkfile.txt","w+"); generate_table(); fclose(fout); /*for(i=0;i<59;i++) { for(j=0;j<68;j++) fprintf(fout,"%d ",Table[i][j]); fprintf(fout,"\n"); }*/ readRules(); fout=fopen("Output.txt","w+"); int tokNo=0,grammarNo,p; push(100); int loopcount=0,currentHash; while(top<1001) { loopcount++; if(top==1001 && tokNo==count) return 0; else if(top==1001 && tokNo!=count) return -1; else if(top!=1001 && tokNo==count) return -1; printStack(); fprintf(fout,"table value is %d where non terminal is %d and token is %d and token no is %d\n",Table[head()-100][hashedTokens[tokNo]+1],head(),hashedTokens[tokNo]+1,tokNo); grammarNo=Table[head()-100][hashedTokens[tokNo]+1]-1; //PUSHING //pop() p=0; while(Rules[grammarNo][p++]!=-1); p--; pop(); for(i=p-1;i>0;i--) { fprintf(fout,"pushing %d\n",Rules[grammarNo][i]); push(Rules[grammarNo][i]); } if(head()==67) { fprintf(fout,"Popping Ebsilon\n"); pop(); } while(1 && tokNo<count && top<1001) { if(head()<100 && head()>=0) { fprintf(fout,"head inside small loop is %d and token is %d\n",head(),hashedTokens[tokNo]); if(head()==hashedTokens[tokNo]) { fprintf(fout,"Poppping %d\n",head()); pop(); tokNo++; } else { fprintf(fout,"Wrong Terminal \n"); pop(); tokNo++; } } else break; } } return 0; }
/*----------------------------------------------------------------------* * Create a Timezone object from time change rules stored in EEPROM * * at the given address. * *----------------------------------------------------------------------*/ Timezone::Timezone(int address) { readRules(address); }