Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > Центр помощи > Как прокомментировать код


Автор: kostyantmb 30.5.2006, 18:47
Помогите, надо построчно прокомментировать код программы, реализующей метод операторного предшествования? Хотя бы просто комментарии...
Код



OpPrSintax::OpPrSintax(void)
{
}

OpPrSintax::~OpPrSintax(void)
{
}

int OpPrSintax::QM(Lexema left, Lexema right)
{
int ln=0, rn=0;
ln=left.number;
rn=right.number;
if(left.type==Var) ln=18;
if(right.type==Var) rn=18;
if(left.type==Con) ln=19;
if(right.type==Con) rn=19;

return opmap[ln][rn];
}

void OpPrSintax::outLexemas(int from, int to, Lexems* Lexemas)
{
int dif=to-from;
for(int i=from; i<to; i++)
{
cout<<(*Lexemas)[i]<<" ";
resu1.push_back((*Lexemas)[i]);
}
cout<<"\n";
for(int i=from; i<Lexemas->size()-dif;i++)
{
(*Lexemas)[i]=(*Lexemas)[i+dif];
}
for(int i=0; i<dif; i++)
{
Lexemas->pop_back();
}

}

Lexems OpPrSintax::Analize(Lexems data)
{
resu1.clear();
Lexema att;
att.type=Op; att.number=0; att.value=-1;
data.push_back(att); 


do
{


int a=-1,b=-1;

for(int i=1; i<data.size(); i++)
{
//cout<<"F:"<<data[i-1]<<" "<<data[i]<<" "<<QM(data[i-1], data[i])<<"\n";
if( QM(data[i-1], data[i])==2)
{
//cout<<"F:"<<data[i-1]<<" "<<data[i]<<" "<<QM(data[i-1], data[i])<<"\n";
b=i;break;
}
if( QM(data[i-1], data[i])==0)
{
cout<<"Simbols:"<<data[i-1]<<" "<<data[i]<<" "<<"can`t be near\n";
b=i;break;
}
}

if(b==-1)
{ cout<<"\nNo found >\n"; break;}


//cout<<"\nb="<<b<<"\n";
for(int i=b-1; i>0; i--)
{
//cout<<"R:"<<data[i-1]<<" "<<data[i]<<" "<<QM(data[i-1], data[i])<<"\n";
if( QM(data[i-1], data[i])==1)
{
//cout<<"R:"<<data[i-1]<<" "<<data[i]<<" "<<QM(data[i-1], data[i])<<"\n";
a=i;break;
}
}

if(a==-1) 
{
if(data[0].type==Op && data[1].type==Op && data[0].number==0 && data[1].number==0 && data.size()>1)
{
outLexemas(0,1,&data);
continue;
}
else 
{
cout<<"\nNo found <\n";
break;
}
}

outLexemas(a,b,&data);



char str[256];
//cin.read(str,1);
}while(arrtest(&data)!=0);

cout<<"Res:"<<resu1;
return resu1;
}

int OpPrSintax::arrtest(Lexems* Lexemas)
{
int rez=0;
for(int i=0; i<Lexemas->size(); i++)
{
if((*Lexemas)[i].type==Op && (*Lexemas)[i].number==0)
{
}
else
{
rez=1;
break;
}
}

return rez;
}
 

Автор: B3cK 30.5.2006, 22:54
Покажи что ли весь класс... 

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)