Nusrat_Ullah

Token Identifier

Feb 21st, 2021
678
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5.     int i,j;
  6.     string a,str,s="+-*/=",op[]={"Addition","Subtraction","Multiply","Division","Assignment"};
  7.     getline(cin,a);
  8.     for(i=0;i<a.length();i++){
  9.         if(isalpha(a[i])){
  10.             printf("%c",a[i++]);
  11.             while((isalpha(a[i])||isdigit(a[i]))&&a[i])
  12.                 printf("%c",a[i++]);
  13.             printf(" = is an identifier\n");
  14.             i--;
  15.         }
  16.         else if(isdigit(a[i])){
  17.             printf("%c",a[i++]);
  18.             while(isdigit(a[i])&&a[i])
  19.                 printf("%c",a[i++]);
  20.             printf(" = is a number\n");
  21.             i--;
  22.         }
  23.         else if(a[i]==';')printf("; = End of line\n");
  24.         else{
  25.             for(j=0;s[j];j++){
  26.                 if(s[j]==a[i]){
  27.                     printf("%c = %s Operator\n",a[i],op[j].c_str());
  28.                     break;
  29.                 }
  30.             }
  31.         }
  32.     }
  33.     return 0;
  34. }
  35.  
RAW Paste Data