Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <regex>
  4. #include <vector>
  5.  
  6. using namespace std;
  7.  
  8. struct Lexer {
  9. vector<string> rule;
  10. vector<string> replacement;
  11. };
  12.  
  13. string Parser(string words, Lexer* Rules) {
  14.  
  15. //unsigned long length = Rules->rule.size();
  16. for (unsigned i = 0; i < Rules->rule.size(); i++) {
  17. regex rule(Rules->rule[i]);
  18. words = regex_replace(words, rule, Rules->replacement[i]);
  19. }
  20.  
  21. return words;
  22. }
  23.  
  24. void init(Lexer* Rules) {
  25. Rules->rule = { "(\W[A-a]\W)", "\W[A-a] \W", "\W [A-a]\W", "^([A-a])", "(\W[A-a])+$",
  26. "(\W[A-a]n\W)", "\W[A-a]n \W", "\W [A-a]n\W", "^([A-a]n)", "(\W[A-a]n)+$",
  27. "(\W[T-t]he\W)", "\W[T-t]he \W", "\W [T-t]he\W", "^([T-t]he)", "(\W[T-t]he)+$",
  28. "(C|c)i", "(C|c)e", "(C|c)k", "(C|c)",
  29. "(E|e){2}", "(O|o){2}", "([a-zA-Z]{2,2})*1" // замена любых одинаковых букв
  30. };
  31. Rules->replacement = { "", " ", " ", "", "", // [5] ( [A-a])+$
  32. "", " ", " ", "", "",
  33. "", " ", " ", "", "",
  34. "s", "s", "", "k",
  35. "i", "u", "+" //"+" подстановка для двух одинаковых букв.
  36. };
  37. }
  38.  
  39. void output(string words) {
  40. cout << words << endl;
  41. }
  42.  
  43. int main()
  44. {
  45. Lexer* Rules = new Lexer();
  46.  
  47. string words;
  48. getline(cin, words);
  49.  
  50. ::init(Rules);
  51. words = ::Parser(words, Rules);
  52. output(words);
  53.  
  54. return 0;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement