fork download
  1. import re
  2.  
  3. import nltk
  4.  
  5. input_program = input("Enter Your Code: ");
  6. input_program_tokens = nltk.wordpunct_tokenize(input_program);
  7.  
  8. print(input_program_tokens);
  9.  
  10.  
  11. RE_Keywords = "auto|break|case|char|const|continue|default|do|double|else|enum|extern|float|for|goto|if|int|long|register|return|short|signed|sizeof|static|struct|switch|typedef|union|unsigned|void|volatile|while|string|class|struc|include"
  12. RE_Operators = "(\++)|(-)|(=)|(\*)|(/)|(%)|(--)|(<=)|(>=)"
  13. RE_Numerals = "^(\d+)$"
  14. RE_Special_Characters = "[\[@&~!#$\^\|{}\]:;<>?,\.']|\(\)|\(|\)|{}|\[\]|\""
  15. RE_Identifiers = "^[a-zA-Z_]+[a-zA-Z0-9_]*"
  16. RE_Headers = "([a-zA-Z]+\.[h])"
  17.  
  18.  
  19. #To Categorize The Tokens
  20.  
  21. for token in input_program_tokens:
  22. if(re.findall(RE_Keywords,token)):
  23. print(token , "-------> Keyword")
  24. elif(re.findall(RE_Operators,token)):
  25. print(token, "-------> Operator")
  26. elif(re.findall(RE_Numerals,token)):
  27. print(token, "-------> Numeral")
  28. elif(re.findall(RE_Special_Characters,token)):
  29. print(token, "-------> Special Character/Symbol")
  30. elif(re.findall(RE_Identifiers,token)):
  31. print(token, "-------> Identifiers")
  32. else:
  33. print("Unknown Value")
  34.  
Success #stdin #stdout #stderr 0.02s 6920KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/eawwI0/prog:33:30: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit