Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- vector<string> k;
- vector<char>id;
- vector<char>lo;
- vector<char>ma;
- vector<string>nu;
- vector<char>ot;
- int main()
- {
- ifstream fin("input.txt");
- char logical_op[] = ">!^&|<", math_op[]="+-*/=", numer[]=".0123456789", other[]=",;\(){}[]'':";
- char ch, buffer[15],b[30];
- int mark[1000]= {0};
- int i,j=0;
- int kc=0,ic=0,lc=0,mc=0,nc=0,oc=0,aaa=0;
- while(!fin.eof())
- {
- ch = fin.get();
- for(i = 0; i < 12; ++i)
- {
- if(ch == other[i])
- {
- int aa=ch;
- if(mark[aa]!=1)
- {
- ot.push_back(ch);
- mark[aa]=1;
- ++oc;
- }
- }
- }
- for(i = 0; i < 5; ++i)
- {
- if(ch == math_op[i])
- {
- int aa=ch;
- if(mark[aa]!=1)
- {
- ma.push_back(ch);
- mark[aa]=1;
- ++mc;
- }
- }
- }
- for(i = 0; i < 6; ++i)
- {
- if(ch == logical_op[i])
- {
- int aa=ch;
- if(mark[aa]!=1)
- {
- lo.push_back(ch);
- mark[aa]=1;
- ++lc;
- }
- }
- }
- 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 == ';')
- {
- 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;
- if((ch == ' ' || ch == '\n' || ch == ';') && (aaa != 0))
- {
- b[aaa] = '\0';
- aaa = 0;
- char arr[30];
- strcpy(arr,b);
- nu.push_back(arr);
- ++nc;
- }
- }
- if(isalnum(ch))
- {
- buffer[j++] = ch;
- }
- else if((ch == ' ' || ch == '\n') && (j != 0))
- {
- buffer[j] = '\0';
- j = 0;
- if(buffer[0]>=97 && buffer[0]<=122)
- {
- if(mark[buffer[0]-'a']!=1)
- {
- id.push_back(buffer[0]);
- ++ic;
- mark[buffer[0]-'a']=1;
- }
- }
- }
- }
- for(i=0; i<81; i++) cout<<"-";
- cout<<endl;
- cout<<"|";
- cout<<"symbol";
- for(i=0; i<12; i++) cout<<" ";
- cout<<"|";
- cout<<"symbol_id";
- for(i=0; i<10; i++) cout<<" ";
- cout<<"|";
- cout<<"token_type";
- for(i=0; i<9; i++) cout<<" ";
- cout<<"|";
- cout<<"value";
- for(i=0; i<15; i++) cout<<" ";
- cout<<"|\n";
- for(i=0; i<81; i++) cout<<"-";
- cout<<endl;
- fin.close();
- j=0;
- for(int x=0; x<ic; x++)
- {
- cout<<id[x];
- for(i=0; i<19; i++) cout<<" ";
- cout<<"id_"<<++j;
- for(i=0; i<16; i++) cout<<" ";
- cout<<"Identifiers";
- for(i=0; i<9; i++) cout<<" ";
- cout<<"_";
- for(i=0; i<19; i++) cout<<" ";
- cout<<endl<<endl;
- }
- j=0;
- for(int x=0; x<mc; x++)
- {
- cout<<ma[x];
- for(i=0; i<19; i++) cout<<" ";
- cout<<"op"<<"_"<<++j;
- for(i=0; i<16; i++) cout<<" ";
- cout<<"operator";
- for(i=0; i<12; i++) cout<<" ";
- cout<<"_";
- for(i=0; i<19; i++) cout<<" ";
- cout<<endl;
- cout<<endl;
- }
- for(int x=0; x<lc; x++)
- {
- cout<<lo[x];
- for(i=0; i<19; i++) cout<<" ";
- cout<<"op"<<"_"<<++j;
- for(i=0; i<16; i++) cout<<" ";
- cout<<"operator";
- for(i=0; i<12; i++) cout<<" ";
- cout<<"_";
- for(i=0; i<19; i++) cout<<" ";
- cout<<endl;
- cout<<endl;
- }
- j=0;
- for(int x=0; x<nc; x++)
- {
- int g=nu[x].size();
- cout<<nu[x];
- for(i=0; i<20-g; i++) cout<<" ";
- cout<<"num"<<"_"<<++j;
- for(i=0; i<15; i++) cout<<" ";
- cout<<"number";
- for(i=0; i<14; i++) cout<<" ";
- cout<<nu[x];
- for(i=0; i<20-g; i++) cout<<" ";
- cout<<endl;
- cout<<endl;
- }
- j=0;
- int l=0;
- for(int x=0; x<oc; ++x)
- {
- if(ot[x]==';')
- {
- cout<<ot[x];
- for(i=0; i<19; i++) cout<<" ";
- cout<<"semicolon"<<"_"<<++l;
- for(i=0; i<9; i++) cout<<" ";
- cout<<"semicolon";
- for(i=0; i<11; i++) cout<<" ";
- cout<<"_";
- for(i=0; i<19; i++) cout<<" ";
- cout<<endl;
- cout<<endl;
- }
- else
- {
- cout<<ot[x];
- for(i=0; i<19; i++) cout<<" ";
- cout<<"other"<<"_"<<++j;
- for(i=0; i<13; i++) cout<<" ";
- cout<<"other";
- for(i=0; i<15; i++) cout<<" ";
- cout<<"_";
- for(i=0; i<19; i++) cout<<" ";
- cout<<endl;
- cout<<endl;
- }
- }
- for(i=0; i<81; i++) cout<<"-";
- cout<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement