так оно и уменя работает но только до тех пор пока не добавлю реализацыю этой функции, и это меня в ступор вводит.
вот полный код:
Код:
//#include <limits>
//#include<cstring>
#include<iostream>
//#include<vector>
//#include<fstream>
//#include<cctype>
//#include <cstdlib>
//#include <string>
#include "math.h"
using namespace std;
typedef char* Str;
typedef int TInt;
typedef struct _Lex
{
bool isOp;
int V;
}*Lex;
typedef
struct _NODE
{
struct _Lex* Rez;
struct _Lex* ThisV;
struct _NODE *Left;
struct _NODE *Right;
}* NODE;
bool LastLexIsPrev;
int Regim;
char Buffer[LONG_MAX];
int LastRezult;
long buff_pos;
long limit_pos;
int Prev_Buff;
bool Prev_buff;
Lex LastLex;
bool Get_Buf()//+
{
if (buff_pos==limit_pos)
{
cout<<"#";
char temp[INT_MAX];
cin.get(temp,INT_MAX);
Buffer[1]=Buffer[buff_pos];
long i=0;
long tt = sizeof(temp);
while(i<tt)
{
if(temp[i]==' '){i++; continue;}
Buffer[i+2] = temp[i];
i++;
}
limit_pos=i+2;
}
buff_pos++;
return 1;
}
bool StartCalc();
void Calculator()
{
buff_pos =0;
limit_pos=0;
Prev_Buff=0;
Prev_buff=0;
Regim = 0;
cout<<"constructor()"<<endl;
/*36145*/
string a;
reg:
cout<<"Enter Mode: Normal,Lint,Debug."<<endl;
{cin>>a;
if(a=="Normal") Regim = 0;
else if( a=="Lint") Regim =1;
else if (a=="Debug")Regim=2;
else{cout<<"Regim incorect"<<endl; goto reg;}
}
/*1456*/
buff_pos=0;
LastRezult=0;
LastLexIsPrev=false;
cout<<"LastLexIsPrev = "<<LastLexIsPrev<<endl;
LastLex= NULL;
Get_Buf();
StartCalc();
}
// bool SetS(Str &a){};
Lex NextLex();
bool PrevLex();
bool If_Icmd();
bool If_Comment();
bool Get_Buf();
Lex E();
Lex S();
Lex M();
Lex A();
bool isplus(Lex);
bool ismnos(Lex);
bool ispow(Lex);
bool isleft(Lex);
bool isright(Lex);
Lex NewNe(){ cout<<"New Ne()"<<endl;
Lex T=new _Lex;
T->isOp=1;
T->V= 0;
return T;
};
Lex NewNe(char a){
cout<<endl<<"New Ne( "<<(char)a<<" )"<<endl;
Lex T=new _Lex;
T->isOp=1;T->V='a';return T;};
Lex Oper(Lex,Lex,Lex);
bool Ne(Lex T){return (((T->isOp)==1)&&((T->V)==0));}
bool Is_TInt(Lex);
void Help(){cout<<"help is coming...";}
void Exit(){exit(1);};
char InBuff()
{
if(Prev_buff==1){Prev_buff=0; return Prev_Buff;}
cout<<"inbuff = "<<Buffer[buff_pos]; return (char)Buffer[buff_pos];
};
bool Is_TInt(Lex T)//+
{
bool rez =0;
cout<<"IsInt?"<<endl;
system("pause");
cout<<"read simvol"<<(char)InBuff();
T->V =0;
while(InBuff()=='0')T->isOp=0; Get_Buf();
int size =0;
while((InBuff()>='0')&&(InBuff()<='9'))
{
size++;
rez = 1;
T->isOp=0;
T->V=(T->V)*10 + (InBuff()-'0')%10;
Get_Buf();
}
cout<<endl<<"is namber = "<<T->V<<endl;
return rez;
}
bool If_Icmd()//+
{
cout<<"Is_Icmd?"<<endl;
system("pause");
if (InBuff()=='h')
{ Get_Buf();
if (InBuff()=='e')
{ Get_Buf();;
if (InBuff()=='l')
{ Get_Buf();;
if (InBuff()=='p')
{ Get_Buf();;Help();return 1;}
}
}
}
if (InBuff()=='e')
{ Get_Buf();;
if (InBuff()=='x')
{ Get_Buf();
if (InBuff()=='i')
{ Get_Buf();;
if (InBuff()=='t')
{Exit();return 1;}
}
}
}
if (InBuff()=='q')
{ Get_Buf();;
if (InBuff()=='u')
{ Get_Buf();;
if (InBuff()=='i')
{ Get_Buf();;
if (InBuff()=='t')
{cout<<"Last rezult== "<<(LastLex->isOp==0?LastLex->V:(char)LastLex->V)<<endl;system("pause"); Exit(); return 1;}
}
}
}
return 0;
}
bool If_Comment()//+
{
cout<<"Is Comment?"<<endl;
system("pause");
if (InBuff()=='/')
{ Get_Buf();
if (InBuff()=='*')
{
while(1)
{
Get_Buf();
if(InBuff()== '*')
{ Get_Buf();
if (InBuff()== '/')
{ Get_Buf(); return 1;}
}
}
}
else if (InBuff()=='/')
{ Get_Buf();
while(InBuff()!='\n')Get_Buf();
return 1;
}
}
cout<<"is no comentar "<<endl;
return 0;
}
Lex NextLex()//+
{
cout<<"generate Next Lex"<<endl;
system("pause");
if (LastLexIsPrev==1){cout<<"return Last Lex"<<endl;system("pause"); LastLexIsPrev=0;return LastLex;}
else
{
Lex R;
R= new _Lex;
R->V=0;
R->isOp=0;
cout<<"LastLex == NULL;"<<endl;
system("pause");
int gopa;
do
{
gopa=0;
If_Icmd();
If_Comment();
if ((InBuff()==';')||(InBuff()=='\n')||(InBuff()=='\0')||(InBuff()==',')||(InBuff()=='.')){ Get_Buf();R->isOp=1;R->V=';';break;}
else if(InBuff() == '+'){ Get_Buf();cout<<" + "<<endl;R->isOp = 1;R->V = '+';}
else if(InBuff() == '-'){ Get_Buf();cout<<" - "<<endl;R->isOp = 1;R->V = '-';}
else if(InBuff() == '%'){ Get_Buf();cout<<" % "<<endl;R->isOp = 1;R->V = '%';}
else if(InBuff() == '('){ Get_Buf();cout<<" ( "<<endl;R->isOp = 1;R->V = '(';}
else if(InBuff() == ')'){ Get_Buf();cout<<" ) "<<endl;R->isOp = 1;R->V = ')';}
else if(InBuff() == '/'){ Get_Buf();cout<<" / "<<endl;R->isOp = 1;R->V = '/';}
else if(InBuff() == '^'){ Get_Buf();cout<<" ^ "<<endl;R->isOp = 1;R->V = '^';}
else if(InBuff() == '*'){ Get_Buf();
if(InBuff() == '*'){ Get_Buf();; cout<<" ^ "<<endl; R->isOp=1;R->V='^';}
else {cout<<" * "<<endl;R->isOp=1;R->V='*';Prev_Buff=InBuff(); Prev_buff =1;}
}
else if(Is_TInt(R)==1){R->isOp=0;cout<<" is realy int "<<endl;}
else {gopa=1;Get_Buf();cout<<" is musor "<<endl;}
cout<<"gopa="<<gopa<<endl;
}while(gopa==1);
if(R->isOp==0)
{cout<<"Next Lex()= "<<R->V<<endl;}
else {cout<<"Next Lex()= "<<(char)R->V<<endl;}
LastLex=R;
return R;
}
}
bool StartCalc()//+
{
Lex T;
cout<<"Start Calc..."<<endl<<endl;
system("pause");
while(1)
{
cout<<"New Expiriens"<<endl;
T=E();
if(T==NULL)cout<<"\nERROR\n";
else
{
if(T->isOp==1){ cout<<"reaultat******=====\n 0 \n ========*****========="<<endl;NextLex();continue;}
LastRezult = T->V;
cout<<endl<<"reaultat******====="<<endl<<T->V<<endl<<"========*****========="<<endl;
NextLex();
}
}
}
Lex E()//+
{
cout<<"Start E()"<<endl;
system("pause");
Lex ET,ER,EL;
ER = S();
EL = NextLex();
while(isplus(EL))
{
ET=S();
ER=Oper(ER,ET,EL);
EL=NextLex();
}
PrevLex();
cout<<"End E()"<<endl;
system("pause");
return ER;
}
Lex S()//+
{
cout<<"Start S()..."<<endl;
system("pause");
Lex SR,SL,ST;
SR=M();
SL=NextLex();
while(ismnos(SL))
{
ST=M();
SR=Oper(SR,ST,SL);
SL=NextLex();
}
PrevLex();
cout<<"End S()"<<endl;
system("pause");
return SR;
}
Lex M()//+
{
cout<<"Start M()"<<endl;
system("pause");
Lex MR,ML;
MR=A();
ML=NextLex();
if(ispow(ML))
{
if(Ne(ML)) return M();
else MR=Oper(MR,M(),ML);
}
else PrevLex();
cout<<"End M()"<<endl;
system("pause");
return MR;
}
Lex A()//+
{
cout<<"Start A()"<<endl;
system("pause");
Lex AR,AE,AT;
AR=NextLex();
if(isleft(AR))
{
AE=E();
AT=NextLex();
if(isright(AT))
{AR=Oper(AE,AT,AR);
}
else {
AR=Oper(AE,AE,NewNe(')'));
}
}
else if(AR->isOp==0)cout<<endl<<"is INT = "<<AR->V<<endl;
else{AR=NewNe();PrevLex();}
cout<<"End A()"<<endl;
system("pause");
return AR;
}
bool isplus(Lex T)//+
{
cout<<"is+ ?"<<endl;
system("pause");
bool t=(T->isOp==1)&&((T->V=='+')||(T->V=='-'));
if (t) cout<<"is realy +"<<endl;
else cout<<"is not +"<<endl;
return t;
}
bool ismnos(Lex T)//+
{
cout<<"is* ?"<<endl;
system("pause");
bool t= (T->isOp)&&((T->V=='*')||(T->V=='/')||(T->V=='%'));
if (t) cout<<"is realy *"<<endl;
else cout<<"is not *"<<endl;
return t;
}
bool ispow(Lex T)//+
{
cout<<"is^ ?"<<endl;
system("pause");
bool t=(T->isOp)&&(T->V=='^');
if (t) cout<<"is realy ^"<<endl;
else cout<<"is not ^"<<endl;;
return t;
}
bool isleft(Lex T)//+
{
cout<<"is '(' ?"<<endl;
system("pause");
bool t;
if ((T->isOp)&&(T->V==(int)'('))
{t=1; cout<<"is realy '('"<<endl;}
else {t=0;cout<<"is not '('"<<endl;}
return t;
}
bool isright(Lex T)//+
{
cout<<"is ')' ?"<<endl;
system("pause");
bool t;
if ((T->isOp)&&(T->V==(int)')'))
{t=1; cout<<"is realy ')'"<<endl;}
else {t=0;cout<<"is not ')'"<<endl;}
return t;
}
Lex Oper(Lex L,Lex R,Lex OP)//+
{
cout<<"Calculte Operation"<<endl;
if(OP->isOp==0) cout<<"Hrenovo.. shos naputav z operatciami"<<endl; system("pause");
Lex Rez = new _Lex;
Rez->isOp =0;
if(Ne(L)&&Ne(R)){Rez->isOp=1;Rez->V=0;}
else
if(Ne(L)){Rez=L;}
else
if(Ne(R)){Rez=R;}
else
if(OP->V=='+') Rez->V=L->V + R->V;
else
if(OP->V=='-') Rez->V=L->V - R->V;
else
if(OP->V=='*') Rez->V=L->V * R->V;
else
if(OP->V=='/')
if(R->V==0){return R;}
else {Rez->V=L->V / R->V;}
else
if(OP->V=='%') Rez->V=L->V % R->V;
else
if(OP->V=='^'){
if(R->V<0) return L;
Rez->V=(long long)pow((double)L->V,(double)R->V);
}
else {cout<<"PPc Musor"<<endl;Rez->isOp=1;Rez->V=0;}
cout<<"End Oper()"<<endl;
system("pause");
return Rez;
}
bool PrevLex()//+-
{
cout<<"prevlex()"<<endl;
system("pause");
LastLexIsPrev=1;
return 1;
}
int main()
{
cout<<"im hear"<<endl;
system("pause");
Calculator();
system("pause");
return 0;
}
Оно компилюется но даже надпись "im hear" невыдает.