Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "Interpreter.h"
- Interpreter::Interpreter(Memory& Mem)
- {
- M = Mem;
- P.SetExpr(" ","'");
- id_loop=-1;
- }
- void Interpreter::SendText(string Value)
- {
- if(Value.length()>0)
- {
- vector <string> A;
- P.ParseText(Value,A);
- if(loop==1)
- {
- Loops[id_loop].push_back(Value);
- cout<<"Wyjście: "<<id_loop<<endl;
- if(A[0] =="endloop")
- {
- for(int i=0; i<loopc[id_loop]; i++)
- {
- // cout<<"Pętla :"<<i<<":"<<endl;
- for(int c =0; c<Loops[id_loop].size(); c++)
- {
- vector <string> d;
- cout<<"Wyjście: "<<id_loop<<endl;
- P.ParseText(Loops[id_loop][c],d);
- Interprate(d);
- cout<<"Wyjście : "<<id_loop<<endl;
- // cout<<endl;
- }
- }
- // Loops.pop_back();
- //loopc.pop_back();
- if(id_loop>-1)id_loop--;
- if(id_loop==-1)loop=0;
- }
- }
- else
- Interprate(A);
- }
- for (int a =0;a<Loops.size();a++)
- {
- for (int b=0;b<Loops[a].size();b++)
- {
- cout<<a<<"."<<b<<" "<<Loops[a][b]<<endl;
- }
- }
- }
- void Interpreter::Interprate(vector<string> Values)
- {
- if(Values[0]=="def")
- if(Values[1].length()>0 and (Values[2]=="number" or Values[2]=="string"))
- {
- if((int)Values[1].find(".")==-1)
- M.AllocData(Values[1],Values[2]);
- }
- if(Values[0]=="set")
- if(Values[1].length()>0 and (Values[2].length()>0))
- {
- M.SetData(Values[1],Values[2]);
- }
- if(Values[0]=="copy")
- if(Values[1].length()>0 and Values[2].length()>0)
- {
- if(M.GetType(Values[1])==M.GetType(Values[2]))
- {
- M.SetData(Values[2],M.GetData(Values[1]));
- }
- }
- if(Values[0]=="print")
- if(Values[1].length()>0 )
- {
- cout<<M.GetData(Values[1]);
- if(Values[2] == "endl")
- cout<<endl;
- }
- if(Values[0]=="input")
- if(Values[1].length()>0 and (Values[2]=="l" or Values[2]=="n") )
- {
- string zm;
- if(Values[2]=="l")
- getline(cin,zm);
- if(Values[2]=="n")
- cin>>zm;
- M.SetData(Values[1],zm);
- }
- if(Values[0]=="loop")
- if(Values[1].length()>0 and M.GetType(Values[1])=="number")
- {
- int tpm =0;;
- istringstream a(M.GetData(Values[1]));
- a>>tpm;
- loop =1;
- id_loop++;
- Loops.resize(id_loop+1);
- loopc.push_back(tpm);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement