Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <regex>
- #include <vector>
- using namespace std;
- struct Lexer {
- vector<string> rule;
- vector<string> replacement;
- };
- string Parser(string words, Lexer* Rules) {
- //unsigned long length = Rules->rule.size();
- for (unsigned i = 0; i < Rules->rule.size(); i++) {
- regex rule(Rules->rule[i]);
- words = regex_replace(words, rule, Rules->replacement[i]);
- }
- return words;
- }
- void init(Lexer* Rules) {
- Rules->rule = { "(\W[A-a]\W)", "\W[A-a] \W", "\W [A-a]\W", "^([A-a])", "(\W[A-a])+$",
- "(\W[A-a]n\W)", "\W[A-a]n \W", "\W [A-a]n\W", "^([A-a]n)", "(\W[A-a]n)+$",
- "(\W[T-t]he\W)", "\W[T-t]he \W", "\W [T-t]he\W", "^([T-t]he)", "(\W[T-t]he)+$",
- "(C|c)i", "(C|c)e", "(C|c)k", "(C|c)",
- "(E|e){2}", "(O|o){2}", "([a-zA-Z]{2,2})*1" // замена любых одинаковых букв
- };
- Rules->replacement = { "", " ", " ", "", "", // [5] ( [A-a])+$
- "", " ", " ", "", "",
- "", " ", " ", "", "",
- "s", "s", "", "k",
- "i", "u", "+" //"+" подстановка для двух одинаковых букв.
- };
- }
- void output(string words) {
- cout << words << endl;
- }
- int main()
- {
- Lexer* Rules = new Lexer();
- string words;
- getline(cin, words);
- ::init(Rules);
- words = ::Parser(words, Rules);
- output(words);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement