PDA

Tam Sürümünü Görmek İçin : son loop da hata


Lewissi
12/12/2005, 23:58
merhabalar,
asagidaki ilk parca text dosyası.input olarak veriliyor.son loopda istedigimi yapamiyorum.simdi programim soyle:

parentezsizler vector<string> ve icinde input dosyamin function f ( float b , mytype c ) kismindan itibaren her satir bir eleman ama } ve { satirlari yok.
yani alinan ilgili her satir vectorun bir elemani. bu vectoru bastirinca da icindekileri anlayabilirsiniz. iste son loopda ben bu vectorden satir satir elemanlari indceliyorum. first dedigim string satirin ilk bosluga kadar olan kismi
mesela ilk satir icin "function". second da benzer sekilde "f" .BENIM AMACIM FONKSIYONLARI VE BU FONKSIYONLARIN CAGIRDIGI FONKSIYONLARI BELIRLEMEK. bunun icin bir struct olusturdum adi fonksiyonum .icinde "adim" ve "vector<string> elemanlarim" var. mesela ilk function f icin adim=f elemanlarim vectoru ise bos olacak. ya da function g icin icin adim=g elemanlarim f olacak.
bir de kolaylık olsun diye parantezszler vectorune "dummy line " ekledim.
loopda her seferinde bi sonraki satira bakiyorum. eger yeni bir function geliyorsa ya da "dummy line " geldiyse yani input bittiyse arada olusturdugum fonksiyonum yapisini bir vectore atip kaydediyorum. boylece isimi halletmis olacagim. ama bir turlu beceremedim. benim gozumden kaca nedir?

type int ;
type float ;
type mytype ;
type itisatype ;
mytype a , mt ;
int x ;
function f ( float b , mytype c )
{
itisatype var ;
double t ;
}
function g ( float b )
{
mytype variable ;
f ( b , variable ) ;
}
function main ( )
{
float ali , veli ;
float b ;
int d ;
g ( a ) ;
f ( c , mt ) ;
g ( c ) ;
}





#include<iostream>

using namespace std;

#include<fstream>

#include<vector>

#include<string>



string sokAl(string s,string key,int keyLen,string ret)

{char c;

int strl;

char *cp;

int tem;

cp=strstr(s.c_str(),key.c_str());

if(cp == NULL)

return "yanlis";

else if(*cp != (s.c_str())[0])

{

return "yanlis";

}

cp += keyLen;

cp++;

strl=strlen(s.c_str());

tem=strl-(keyLen-1);

for(int r=0;r<tem;r++)

{

if(*cp != ' ')

{ret.push_back(*cp);

cp++;

}

else return ret;

}

return ret;

}

string cevir_lower(string s)

{

int len;

string temp;

char *cp;

// cp=s.c_str();

len=strlen(s.c_str() );

char cstr[len];

char lowlar[len];

for(int w=0;w<len;w++)

cstr[w]=s.at(w);

for(int x=0;x<len;x++)

lowlar[x]=tolower(cstr[x]);



for(int u=0;u<len;u++)

temp.push_back( lowlar[u] );

s=temp;

return s;

}



class degisken{

public:

string name;

string scope;

string type;

degisken(string itsName="someName",string itsScope="someScope", string itsType="someType"){

name=itsName;

scope=itsScope;

type=itsType;

}

degisken(){

name="someName";

scope="someScope";

type="someType";

}

~degisken(){}

};/*

class fonksiyonum{

public:

string adim;

vector<string>elemanlarim;

fonksiyonum(string a,string b ){

adim=a;

elemanlarim.push_back(b);

}

fonksiyonum(){

adim="NONAME";

elemanlarim.push_back("NOFUNCTION");

}

~fonksiyonum(){}

};*/

struct fonksiyonum{

public:

string adim;

vector<string>elemanlarim;

};



/*

bool isMember(string aranan,vector<string>aranilan)

*/

/*

string getGlobals(string line,vector<degisken> global_var,string dum)

*/

bool ismember(string sr,vector<string> vc)

{



for(int y=0;y<vc.size();y++)

if(sr == vc.at(y))

return true;

else continue;



return false;

}



int main () {



string r;

string al;

vector<string>read_types;

vector<string>read_variables;

vector<string>read_functions;

string line,type;



ifstream myfile ("lower3.txt");

if (myfile.is_open())

{

while (! myfile.eof())

{getline (myfile,line);

if(! (line.empty()))

{

if( sokAl(line,"type",4,r) != "yanlis")

{

read_types.push_back(sokAl(line,"type",4,r) );

}

}

}}

// for(int y=0;y<read_types.size();y++)

// {cout<<read_types.at(y)<<endl;

// }

string bosluk=" ";

string satir,functions;

ifstream func_file ("lower3.txt");

if (func_file.is_open())

{

while (! func_file.eof())

{getline (func_file,satir);

if(! (satir.empty()))

{

if( sokAl(satir,"function",8,r) != "yanlis")

{read_functions.push_back( sokAl(satir,"function",8,r) );

}}}

}

// for(int y=0;y<read_functions.size();y++)

// {cout<<read_functions.at(y)<<endl;

// }

//////////////////////////////////////////

int q;

string satirva,dum;

vector<degisken>global_var;

string f,g;

vector<string> globaller;

char *kontrol;

string adi="",tipi="";

string t="";

ifstream ifs ("lower3.txt");

vector<string>okubakam;

string okuyom;

if (ifs.is_open()){

while (! ifs.eof())

{getline (ifs,okuyom );

if(! (okuyom.empty())){

okubakam.push_back(okuyom);

}

}}

ifs.close();

// for(q=0;q<okubakam.size();q++)

// cout<<okubakam.at(q)<<endl;

//////////////////////////////////////////

bool kont;

string gettype;

for(q=0;q<okubakam.size();q++)

{

int yer;

yer=(okubakam.at(q)).find(" ",0);

gettype=(okubakam.at(q)).substr(0,yer);

// cout<<"$"<<gettype<<"$"<<endl;

kont= (gettype != "type");

if(kont)

{ if(gettype != "function" )

{

cout<<okubakam.at(q) <<endl;

globaller.push_back ( okubakam.at(q) );

}

else break;

}



}

// cout<<globaller.size()<<endl;

// for(q=0;q<globaller.size();q++)

// cout<<globaller.at(q)<<endl;

///////////////////////////////////////////////

cout<<"control edildi"<<endl;

string a,b;

int e;

int yer,yer2;

for(e=0;e<globaller.size();e++ ){

a=globaller.at(e);

//a = "int ali , veli , deli ;";

yer = a.find(" ",0);

b = a.substr(0,yer);

// cout <<"type is " << b <<endl;

string tipi;

tipi=b;

for(; ;) { if (yer >= (a.length() - 2)) break;

yer++;

yer2 = a.find(" ",yer);

b = a.substr(yer,yer2-yer);

// cout << b <<endl;

degisken temp(b,"GLOBAL",tipi );

global_var.push_back(temp);

yer = a.find(" ",yer2);

yer+=2;}}

cout<<"wwwwwwwwwwwwfffffffffffffggggggggggggggghhhhhhhhhh"<<endl;

for(int g=0;g<global_var.size();g++)

{ cout<<(global_var.at(g)).name<<endl;

cout<<(global_var.at(g)).scope<<endl;

cout<<(global_var.at(g)).type<<endl;

}



cout<<"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"<<endl;

vector<degisken> fonktaki;



for(int u=0;u<okubakam.size();u++){

string a2,b2;

int yer21,yer22;

a2 = okubakam.at(u);

yer21 = a2.find(" ",0);

b2 = a2.substr(0,yer21);

// burda function mu degil mi kontrol edebilirsin..

if(b2=="function")

{

yer21++;

yer22 = a2.find(" ",yer21);

b2 = a2.substr(yer21,yer22-yer21);

// if(b2=="main")

// continue;

yer21 = yer22;

yer21 += 2;

string sco=b2;

for(; ;) {

yer21++;

if (yer21 >= (a2.length() - 2)) break;

// yer21++;

yer22 = a2.find(" ",yer21);

b2 = a2.substr(yer21,yer22-yer21);

string tr=b2;

yer22++;

yer21 = a2.find(" ",yer22);

b2 = a2.substr(yer22,yer21-yer22);

string aw=b2;

yer21+=2;

degisken temp2(aw,sco,tr);

fonktaki.push_back(temp2);

}

}

}

/////////////////////////////////////////////////////ok

cout<<"wwwwwwwwwwwwwwwwwwwwwwwww"<<endl;

int counterglo=0;

for(int hj=0;hj<okubakam.size();hj++)

{



int yq=(okubakam.at(hj)).find(" ",0);

string dq=(okubakam.at(hj)).substr(0,yq);

if( dq != "function")

counterglo++;

else break;

}

cout<<counterglo<<endl;

///////////////////////////////

cout<<"zzzzzzzzzzzzzzzzzzzzzzzzzz"<<endl;

//for(int er=0;er<okubakam.size();er++)

//cout<<okubakam.at(er)<<endl;



///////////

vector<string> parantezsiz;

for(int d=counterglo;d<okubakam.size();d++)

{

string cizgi;

cizgi=okubakam.at(d);

//cout<<"$"<<cizgi<<"$"<<endl;

if(cizgi == "{" || cizgi == "}")

continue;

else

parantezsiz.push_back(cizgi);



}

cout<<"ppppppppppppppppppppppppppppp"<<endl;

// for(int ert=0;ert<parantezsiz.size();ert++)

//cout<<parantezsiz.at(ert)<<endl;

string scop;

vector<degisken> of;

for(int wer=0;wer<parantezsiz.size();wer++)

{

string ilki,ikinci,sat,isim,tpi;

int bos1,bos2;



sat=parantezsiz.at(wer);

bos1=sat.find(" ",0);

ilki=sat.substr(0,bos1);

if(ilki=="function")

{

bos2=sat.find(" ",bos1+1);

ikinci=sat.substr(bos1,(bos2-bos1));

scop=ikinci;

continue;

}

if(ismember(ilki,read_functions))

{

continue;

}

tpi=ilki;

for(;;)

{

if (bos1 >=(sat.length()-2)) break;

bos1++;

bos2=sat.find(" ",bos1);

ilki=sat.substr(bos1,bos2-bos1);

degisken temp31(ilki,scop,tpi);

of.push_back(temp31);

bos2++;// yoktu burda

bos1=sat.find(" ",bos2);

bos2+=3;// 2 idi

}

for(int m=0;m<of.size();m++)

{

cout<<(of.at(m)).name<<endl;

cout<<(of.at(m)).scope<<endl;

cout<<(of.at(m)).type<<endl;

}

int dur=getchar();

}

cout<<of.size()<<endl;

//

cout<<"oooooooooooooooooooooooooooooooooooooooooooooooooo oo "<<endl;

for(int l=0;l<read_functions.size();l++)

cout<<read_functions.at(l)<<endl;

cout<<"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzxxxxxxxxxxxxx xxxxxxxxxxx "<<endl;

string scop2;

vector<fonksiyonum>fler;

vector<degisken> of2;

fonksiyonum yapim;

parantezsiz.push_back("Dummy Line");

cout<<parantezsiz.at(0)<<endl;

for(int wer2=0;wer2<parantezsiz.size()-1;wer2++)

{

string first,second,misra,scopum;

int hole1,hole2;

misra=parantezsiz.at(wer2);

hole1=misra.find(" ",0);

hole1++;

first=misra.substr(0,hole1);

hole2=misra.find(" ",hole1+1);

second=misra.substr(hole1,(hole2-hole1));

cout<<first<<" "<<second<<endl;

if(first=="function")

{

scopum=second;

hayri.adim=scopum;

hayri.elemanlarim.push_back("NOFUNC");

continue;

}

else {

if((((parantezsiz.at(wer2+1)).substr(0,((parantezs iz.at(wer2+1)).find(" ",0)))) =="function"))

{

fler.push_back(yapim);

continue;

}

else if((((parantezsiz.at(wer2+1)).substr(0,((parantezs iz.at(wer2+1)).find(" ",0)))) =="Line"))

{

fler.push_back(yapim);

break;

}



else

{

if(second=="(")

{

yapim.elemanlarim.push_back(first);

}else continue;

}

}

}

///////////////////////

cout<<" llllllllllllllllllllll "<<endl;

cout<<"aaaaaaaabbbbbbbb "<<fler.size()<<endl;

cout<<" hebeeee "<<(fler.at(0)).adim<<endl;

cout<<" hebeeee wwwww "<<(fler.at(1)).adim<<endl;



/*

for(int ups=0;ups<fler.size();ups++)

{

cout<<"fonk :::"<<(fler.at(ups)).adim<<endl;

for(int yuh=0;yuh<((fler.at(ups)).elemanlarim).size();yuh++)

cout<<"elemanlar "<<((fler.at(ups)).elemanlarim).at(yuh)<<endl;



}

*/



return 0;

}


acehreli
15/12/2005, 01:03
Tam olarak neyin calismadigini anlamadim ama gorebildigim bir sey, 'yapim' adli nesnenin ogelerini hic degistirmiyorsun. Onun icin fler'in ici bos gorunuyordur.

Ote yandan orada hayri diye tanimsiz bir nesne var; belki de o mu 'yapim' olacak?

Ali

Lewissi
15/12/2005, 03:32
sorunu hallettim. stringlerin sonuna bos karakter de ekliyormusum.