Advertisement
Mohammad_Dipu_Sultan

Untitled

Apr 22nd, 2022
1,208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.43 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4. vector<string> k;
  5. vector<char>id;
  6. vector<char>lo;
  7. vector<char>ma;
  8. vector<string>nu;
  9. vector<char>ot;
  10.  
  11.  
  12. int main()
  13. {
  14.     ifstream fin("input.txt");
  15.     char logical_op[] = ">!^&|<", math_op[]="+-*/=", numer[]=".0123456789", other[]=",;\(){}[]'':";
  16.     char ch, buffer[15],b[30];
  17.     int mark[1000]= {0};
  18.    
  19.     int i,j=0;
  20.     int kc=0,ic=0,lc=0,mc=0,nc=0,oc=0,aaa=0;
  21.    
  22.     while(!fin.eof())
  23.     {
  24.         ch = fin.get();
  25.         for(i = 0; i < 12; ++i)
  26.         {
  27.             if(ch == other[i])
  28.             {
  29.                 int aa=ch;
  30.                
  31.                 if(mark[aa]!=1)
  32.                 {
  33.                     ot.push_back(ch);
  34.                     mark[aa]=1;
  35.                     ++oc;
  36.                 }
  37.             }
  38.         }
  39.  
  40.         for(i = 0; i < 5; ++i)
  41.         {
  42.             if(ch == math_op[i])
  43.             {
  44.                 int aa=ch;
  45.                 if(mark[aa]!=1)
  46.                 {
  47.                     ma.push_back(ch);
  48.                     mark[aa]=1;
  49.                     ++mc;
  50.                 }
  51.             }
  52.         }
  53.        
  54.         for(i = 0; i < 6; ++i)
  55.         {
  56.             if(ch == logical_op[i])
  57.             {
  58.                 int aa=ch;
  59.                 if(mark[aa]!=1)
  60.                 {
  61.                     lo.push_back(ch);
  62.                     mark[aa]=1;
  63.                     ++lc;
  64.                 }
  65.             }
  66.  
  67.         }
  68.        
  69.         if(ch=='0' || ch=='1' || ch=='2' || ch=='3' || ch=='4' || ch=='5' || ch=='6' || ch=='7' || ch=='8' || ch=='9' || ch=='.' ||ch == ' ' || ch == '\n' || ch == ';')
  70.         {
  71.             if(ch=='0' || ch=='1' || ch=='2' || ch=='3' || ch=='4' || ch=='5' || ch=='6' || ch=='7' || ch=='8' || ch=='9' || ch=='.') b[aaa++]=ch;
  72.             if((ch == ' ' || ch == '\n' || ch == ';') && (aaa != 0))
  73.             {
  74.                 b[aaa] = '\0';
  75.                 aaa = 0;
  76.                 char arr[30];
  77.                 strcpy(arr,b);
  78.                 nu.push_back(arr);
  79.                 ++nc;
  80.             }
  81.         }
  82.  
  83.  
  84.         if(isalnum(ch))
  85.         {
  86.             buffer[j++] = ch;
  87.         }
  88.         else if((ch == ' ' || ch == '\n') && (j != 0))
  89.         {
  90.             buffer[j] = '\0';
  91.             j = 0;
  92.             if(buffer[0]>=97 && buffer[0]<=122)
  93.             {
  94.                 if(mark[buffer[0]-'a']!=1)
  95.                 {
  96.                     id.push_back(buffer[0]);
  97.                     ++ic;
  98.                      mark[buffer[0]-'a']=1;
  99.                 }
  100.             }
  101.            
  102.         }
  103.     }
  104.  
  105.     for(i=0; i<81; i++) cout<<"-";
  106.  
  107.     cout<<endl;
  108.  
  109.     cout<<"|";
  110.  
  111.     cout<<"symbol";
  112.  
  113.     for(i=0; i<12; i++) cout<<" ";
  114.  
  115.     cout<<"|";
  116.  
  117.     cout<<"symbol_id";
  118.  
  119.     for(i=0; i<10; i++) cout<<" ";
  120.  
  121.     cout<<"|";
  122.  
  123.     cout<<"token_type";
  124.  
  125.     for(i=0; i<9; i++) cout<<" ";
  126.  
  127.     cout<<"|";
  128.  
  129.     cout<<"value";
  130.  
  131.     for(i=0; i<15; i++) cout<<" ";
  132.  
  133.     cout<<"|\n";
  134.  
  135.     for(i=0; i<81; i++) cout<<"-";
  136.  
  137.     cout<<endl;
  138.  
  139.     fin.close();
  140.  
  141.     j=0;
  142.  
  143.     for(int x=0; x<ic; x++)
  144.     {
  145.         cout<<id[x];
  146.  
  147.         for(i=0; i<19; i++) cout<<" ";
  148.  
  149.         cout<<"id_"<<++j;
  150.  
  151.         for(i=0; i<16; i++) cout<<" ";
  152.  
  153.         cout<<"Identifiers";
  154.  
  155.         for(i=0; i<9; i++) cout<<" ";
  156.  
  157.         cout<<"_";
  158.  
  159.         for(i=0; i<19; i++) cout<<" ";
  160.  
  161.         cout<<endl<<endl;
  162.  
  163.     }
  164.  
  165.     j=0;
  166.  
  167.     for(int x=0; x<mc; x++)
  168.     {
  169.         cout<<ma[x];
  170.  
  171.         for(i=0; i<19; i++) cout<<" ";
  172.  
  173.         cout<<"op"<<"_"<<++j;
  174.  
  175.         for(i=0; i<16; i++) cout<<" ";
  176.  
  177.         cout<<"operator";
  178.  
  179.         for(i=0; i<12; i++) cout<<" ";
  180.  
  181.         cout<<"_";
  182.  
  183.         for(i=0; i<19; i++) cout<<" ";
  184.  
  185.         cout<<endl;
  186.  
  187.         cout<<endl;
  188.     }
  189.  
  190.     for(int x=0; x<lc; x++)
  191.     {
  192.         cout<<lo[x];
  193.  
  194.         for(i=0; i<19; i++) cout<<" ";
  195.  
  196.         cout<<"op"<<"_"<<++j;
  197.  
  198.         for(i=0; i<16; i++) cout<<" ";
  199.  
  200.         cout<<"operator";
  201.  
  202.         for(i=0; i<12; i++) cout<<" ";
  203.  
  204.         cout<<"_";
  205.  
  206.         for(i=0; i<19; i++) cout<<" ";
  207.  
  208.         cout<<endl;
  209.  
  210.         cout<<endl;
  211.     }
  212.  
  213.     j=0;
  214.     for(int x=0; x<nc; x++)
  215.     {
  216.         int g=nu[x].size();
  217.  
  218.         cout<<nu[x];
  219.  
  220.         for(i=0; i<20-g; i++) cout<<" ";
  221.  
  222.         cout<<"num"<<"_"<<++j;
  223.  
  224.         for(i=0; i<15; i++) cout<<" ";
  225.  
  226.         cout<<"number";
  227.  
  228.         for(i=0; i<14; i++) cout<<" ";
  229.  
  230.         cout<<nu[x];
  231.  
  232.         for(i=0; i<20-g; i++) cout<<" ";
  233.  
  234.         cout<<endl;
  235.  
  236.         cout<<endl;
  237.     }
  238.  
  239.     j=0;
  240.  
  241.     int l=0;
  242.  
  243.     for(int x=0; x<oc; ++x)
  244.     {
  245.         if(ot[x]==';')
  246.         {
  247.             cout<<ot[x];
  248.  
  249.             for(i=0; i<19; i++) cout<<" ";
  250.  
  251.             cout<<"semicolon"<<"_"<<++l;
  252.  
  253.             for(i=0; i<9; i++) cout<<" ";
  254.  
  255.             cout<<"semicolon";
  256.  
  257.             for(i=0; i<11; i++) cout<<" ";
  258.  
  259.             cout<<"_";
  260.  
  261.             for(i=0; i<19; i++) cout<<" ";
  262.  
  263.             cout<<endl;
  264.  
  265.             cout<<endl;
  266.         }
  267.         else
  268.         {
  269.             cout<<ot[x];
  270.  
  271.             for(i=0; i<19; i++) cout<<" ";
  272.  
  273.             cout<<"other"<<"_"<<++j;
  274.  
  275.             for(i=0; i<13; i++) cout<<" ";
  276.  
  277.             cout<<"other";
  278.  
  279.             for(i=0; i<15; i++) cout<<" ";
  280.  
  281.             cout<<"_";
  282.  
  283.             for(i=0; i<19; i++) cout<<" ";
  284.  
  285.             cout<<endl;
  286.  
  287.             cout<<endl;
  288.         }
  289.  
  290.     }
  291.     for(i=0; i<81; i++) cout<<"-";
  292.  
  293.     cout<<endl;
  294.  
  295.     return 0;
  296. }
  297.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement