Summary Files Commits Branches @commit @diff @stats
path: root / src / blog / sane-explanation-of-compilers / part-1 / regex_parser_simple.cpp
blob: c0a5a4ed2541cf3e3b4740a5212e8351c5d12a18 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
bool matchesp(string str) {
    string regex = "acce_t";

    for (int si = 0, ri = 0; si < str.size() && ri < regex.size(); si++, ri++) {
        while (regex[ri] == '_')
            if (str[si] == 'n' || str[si] == 'p')
                si++;
            else
                ri++;
        }

        if (str[si] != regex[ri])
            return false;
    }
    return true;
}