Advertisement
Guest User

C++

a guest
Oct 30th, 2011
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.98 KB | None | 0 0
  1. #include "Interpreter.h"
  2.  
  3. Interpreter::Interpreter(Memory& Mem)
  4. {
  5.     M = Mem;
  6.     P.SetExpr(" ","'");
  7.     id_loop=-1;
  8. }
  9. void Interpreter::SendText(string Value)
  10. {
  11.     if(Value.length()>0)
  12.     {
  13.         vector <string> A;
  14.         P.ParseText(Value,A);
  15.         if(loop==1)
  16.         {
  17.             Loops[id_loop].push_back(Value);
  18.              cout<<"Wyjście: "<<id_loop<<endl;
  19.  
  20.             if(A[0] =="endloop")
  21.             {
  22.  
  23.                 for(int i=0; i<loopc[id_loop]; i++)
  24.                 {
  25.                     // cout<<"Pętla :"<<i<<":"<<endl;
  26.                     for(int c =0; c<Loops[id_loop].size(); c++)
  27.                     {
  28.                         vector <string> d;
  29.                        cout<<"Wyjście: "<<id_loop<<endl;
  30.                         P.ParseText(Loops[id_loop][c],d);
  31.  
  32.                         Interprate(d);
  33.  
  34.                          cout<<"Wyjście : "<<id_loop<<endl;
  35.                         // cout<<endl;
  36.                     }
  37.  
  38.                 }
  39.               // Loops.pop_back();
  40.                //loopc.pop_back();
  41.                if(id_loop>-1)id_loop--;
  42.                 if(id_loop==-1)loop=0;
  43.             }
  44.         }
  45.  
  46.         else
  47.             Interprate(A);
  48.  
  49.     }
  50.     for (int a =0;a<Loops.size();a++)
  51.     {
  52.         for (int b=0;b<Loops[a].size();b++)
  53.         {
  54.             cout<<a<<"."<<b<<" "<<Loops[a][b]<<endl;
  55.         }
  56.     }
  57. }
  58. void Interpreter::Interprate(vector<string> Values)
  59. {
  60.     if(Values[0]=="def")
  61.         if(Values[1].length()>0 and (Values[2]=="number" or Values[2]=="string"))
  62.         {
  63.             if((int)Values[1].find(".")==-1)
  64.                 M.AllocData(Values[1],Values[2]);
  65.         }
  66.     if(Values[0]=="set")
  67.         if(Values[1].length()>0 and (Values[2].length()>0))
  68.         {
  69.             M.SetData(Values[1],Values[2]);
  70.         }
  71.     if(Values[0]=="copy")
  72.         if(Values[1].length()>0 and Values[2].length()>0)
  73.         {
  74.             if(M.GetType(Values[1])==M.GetType(Values[2]))
  75.             {
  76.                 M.SetData(Values[2],M.GetData(Values[1]));
  77.             }
  78.         }
  79.     if(Values[0]=="print")
  80.         if(Values[1].length()>0 )
  81.         {
  82.             cout<<M.GetData(Values[1]);
  83.             if(Values[2] == "endl")
  84.                 cout<<endl;
  85.         }
  86.  
  87.     if(Values[0]=="input")
  88.         if(Values[1].length()>0 and (Values[2]=="l" or Values[2]=="n") )
  89.         {
  90.             string zm;
  91.             if(Values[2]=="l")
  92.                 getline(cin,zm);
  93.             if(Values[2]=="n")
  94.                 cin>>zm;
  95.             M.SetData(Values[1],zm);
  96.         }
  97.         if(Values[0]=="loop")
  98.                 if(Values[1].length()>0 and M.GetType(Values[1])=="number")
  99.                 {
  100.                     int tpm =0;;
  101.                     istringstream a(M.GetData(Values[1]));
  102.                     a>>tpm;
  103.                     loop =1;
  104.                     id_loop++;
  105.                     Loops.resize(id_loop+1);
  106.                     loopc.push_back(tpm);
  107.                 }
  108.  
  109. }
  110.  
  111.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement