Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Using c++11 regex to tokenize input string
- //[0-9]+ = 1 or many digits
- //Or [\-\+\\(\)\/\*] = "-" or "+" or "/" or "*" or "(" or ")"
- std::regex e ( "[0-9]+|[\-\+\\(\)\/\*]");
- std::sregex_iterator rend;
- std::sregex_iterator a( infixExpression.begin(), infixExpression.end(), e );
- queue<string> infixQueue;
- while (a!=rend) {
- infixQueue.push(a->str());
- ++a;
- }
- return infixQueue;
- tring infix; //The string to be parse (the arithmetic operation if you will)
- vector<string> untokenize;
- std::regex words_regex("[0-9]?([0-9]*[.])?[0-9]+|[\-\+\\(\)\/\*]");
- auto words_begin = std::sregex_iterator(infix.begin(), infix.end(), words_regex);
- auto words_end = std::sregex_iterator();
- for (std::sregex_iterator i = words_begin; i != words_end; ++i) {
- cout << (*i).str() << endl;
- untokenize.push_back((*i).str());
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement